Write a program that reads up to 10 numbers per line to be
stored in an array. The program calculates and displays the sum
of the numbers, the mean (arithmetic average) of the numbers,
and the largest and smallest values entered for each line.
Here's the file it reads from:
Code: Select all
45 98 35 23 67 84
65 91 20 54 62 37 65 84 32
21 54 95 87 35 62 54 78
56
95 62 35 54 78
[code]
i've got every except the part where it skips the line when it reaches the end of line..i know it has something to do with the sstream function. any help?
[code]
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main()
{
string sBuf;
int x, i, arnNumber[10][10], nCounter=0, nSum=0, nMax, nMin=99999;
double dMean;
ifstream fin;
ofstream fout;
fin.open("71dIN.txt");
istringstream istr(sBuf);
while(!fin.fail()){
for(x=0; x<10; x++)
{
fin>>arnNumber[nCounter][x];
}
nCounter++;
}
for(x=0; x<nCounter; x++)
{
for(i=0; i<10; i++)
{
nSum += arnNumber[nCounter][i];
if(arnNumber[nCounter][i]>nMax)
{
nMax = arnNumber[nCounter][i];
}
if(arnNumber[nCounter][i] < nMin)
{
nMin = arnNumber[nCounter][i];
}
}
dMean = nSum/10;
cout<<"The sum of line "<<nCounter+1<<" is "<<nSum<<endl;
cout<<"The average of line "<<nCounter+1<<" is "<<dMean<<endl;
cout<<"The largest value of line "<<nCounter+1<<" is "<<nMax<<endl;
cout<<"The smallest value of line "<<nCounter+1<<" is "<<nMin<<endl;
nSum = 0;
}
fin.close();
return 0;
}
[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:4580, old post ID:36475[/size][/color]