Ok fellow programmers
i got this program
file is say (71dIN.txt)
inside file is
now the only problem is is that when i try to find average and total of each line it adds all lines up :S
this is my code
can you guys help if u know the problem... thanks alot
i got this program
file is say (71dIN.txt)
inside file is
Code:
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
this is my code
Code:
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
int main()
{
string sBuf;
int arnNums[50], nSize, i, nHighest = 0, nLowest = 0, nAverage = 0, nTotal = 0, arn[5], n = 0;
ifstream fin("71dIN.txt");
istringstream istr(sBuf);
while(1)
{
getline(fin, sBuf);
istr.clear();
istr.str(sBuf);
if(fin.eof()) break;
i = 0;
while(1)
{
istr >> arnNums[i];
i++;
if(istr.eof()) break;
}
nSize = i;
for(i = 0; i<nSize; i++)
{
nTotal += arnNums[i];
nAverage = nTotal / 4;
cout << arnNums[i] << " ";
}
cout << endl;
for(i = 0; i < 1; i++)
{
cout << "Average is " << nAverage << " and Total is " << nTotal << endl;
cout << endl << endl;
}
}
return 0;
}
Comment