#include <iostream>
#include <fstream>



using namespace std;


int main( )
{
ifstream fin;
ofstream fout;


fin.open("income.dat");
if (fin.fail( ))
{
cout << "Input file opening failed.\n";
exit(1);
}


fout.open("total.dat");
if (fout.fail( ))
{
cout << "Output file opening failed.\n";
exit(1);
}


double next, sum = 0;
int count = 0;
while (fin >> next )
{
sum = sum + next;
count ++;


}



fin.close( );
fout.close( );


cout << "End of program.\n";
return 0;
}

i wan to make a program tat can read all the number in the file.....but it cant .... y?

swt....

forgot to add

fout << sum ;

=="

did you fout << sum ?

yaya....just realise...thx for help.....hmmm.....if i hav number and text in file.dat......how to make it sum up all the number in the file?

for example (xx.dat):
2day 1000
2molo 1000

the code i write can not sum up the number...wat should i change for make it read number only?

What result are you expecting from the example data? 2004?

2000
but tat code i write seem can not read...

sorry...the data example should wirte like this :
today 1000
yesterday 1000

Hope you figured this out already. If not, what basically you need to do is use "get" or "ignore" to eat the word before the number, then you can do your summation as usual.

hmm...i get it a bit....but seem some problem occur again.....i post new 1 out already...thx for u help.....u all r so kind .... ^^