943,876 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 996
  • C++ RSS
Nov 26th, 2007
0

help me...wher i did wrong?

Expand Post »
#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?
Last edited by ricnyx; Nov 26th, 2007 at 5:25 am.
Similar Threads
Reputation Points: 8
Solved Threads: 0
Newbie Poster
ricnyx is offline Offline
21 posts
since Nov 2007
Nov 26th, 2007
0

Re: help me...wher i did wrong?

swt....

forgot to add

fout << sum ;

=="
Reputation Points: 8
Solved Threads: 0
Newbie Poster
ricnyx is offline Offline
21 posts
since Nov 2007
Nov 26th, 2007
0

Re: help me...wher i did wrong?

did you fout << sum ?
Reputation Points: 10
Solved Threads: 2
Newbie Poster
jaux is offline Offline
15 posts
since Oct 2007
Nov 26th, 2007
0

Re: help me...wher i did wrong?

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?
Reputation Points: 8
Solved Threads: 0
Newbie Poster
ricnyx is offline Offline
21 posts
since Nov 2007
Nov 26th, 2007
0

Re: help me...wher i did wrong?

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?
Reputation Points: 8
Solved Threads: 0
Newbie Poster
ricnyx is offline Offline
21 posts
since Nov 2007
Nov 26th, 2007
0

Re: help me...wher i did wrong?

What result are you expecting from the example data? 2004?
Reputation Points: 10
Solved Threads: 2
Newbie Poster
jaux is offline Offline
15 posts
since Oct 2007
Nov 26th, 2007
0

Re: help me...wher i did wrong?

2000
but tat code i write seem can not read...
Reputation Points: 8
Solved Threads: 0
Newbie Poster
ricnyx is offline Offline
21 posts
since Nov 2007
Nov 26th, 2007
0

Re: help me...wher i did wrong?

sorry...the data example should wirte like this :
today 1000
yesterday 1000
Reputation Points: 8
Solved Threads: 0
Newbie Poster
ricnyx is offline Offline
21 posts
since Nov 2007
Nov 27th, 2007
0

Re: help me...wher i did wrong?

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.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
jaux is offline Offline
15 posts
since Oct 2007
Nov 27th, 2007
0

Re: help me...wher i did wrong?

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 .... ^^
Reputation Points: 8
Solved Threads: 0
Newbie Poster
ricnyx is offline Offline
21 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: OpenGl, Visual c++ and textures
Next Thread in C++ Forum Timeline: Legal Bools





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC