954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help me...wher i did wrong?

#include
#include


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?

ricnyx
Newbie Poster
21 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

swt....

forgot to add

fout << sum ;

=="

ricnyx
Newbie Poster
21 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

did you fout << sum ?

jaux
Newbie Poster
15 posts since Oct 2007
Reputation Points: 10
Solved Threads: 2
 

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?

ricnyx
Newbie Poster
21 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

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?

ricnyx
Newbie Poster
21 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

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

jaux
Newbie Poster
15 posts since Oct 2007
Reputation Points: 10
Solved Threads: 2
 

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

ricnyx
Newbie Poster
21 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

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

ricnyx
Newbie Poster
21 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

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.

jaux
Newbie Poster
15 posts since Oct 2007
Reputation Points: 10
Solved Threads: 2
 

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 .... ^^

ricnyx
Newbie Poster
21 posts since Nov 2007
Reputation Points: 8
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You