help me...wher i did wrong?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 21
Reputation: ricnyx is an unknown quantity at this point 
Solved Threads: 0
ricnyx ricnyx is offline Offline
Newbie Poster

help me...wher i did wrong?

 
0
  #1
Nov 26th, 2007
#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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 21
Reputation: ricnyx is an unknown quantity at this point 
Solved Threads: 0
ricnyx ricnyx is offline Offline
Newbie Poster

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

 
0
  #2
Nov 26th, 2007
swt....

forgot to add

fout << sum ;

=="
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: jaux is an unknown quantity at this point 
Solved Threads: 2
jaux's Avatar
jaux jaux is offline Offline
Newbie Poster

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

 
0
  #3
Nov 26th, 2007
did you fout << sum ?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 21
Reputation: ricnyx is an unknown quantity at this point 
Solved Threads: 0
ricnyx ricnyx is offline Offline
Newbie Poster

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

 
0
  #4
Nov 26th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 21
Reputation: ricnyx is an unknown quantity at this point 
Solved Threads: 0
ricnyx ricnyx is offline Offline
Newbie Poster

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

 
0
  #5
Nov 26th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: jaux is an unknown quantity at this point 
Solved Threads: 2
jaux's Avatar
jaux jaux is offline Offline
Newbie Poster

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

 
0
  #6
Nov 26th, 2007
What result are you expecting from the example data? 2004?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 21
Reputation: ricnyx is an unknown quantity at this point 
Solved Threads: 0
ricnyx ricnyx is offline Offline
Newbie Poster

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

 
0
  #7
Nov 26th, 2007
2000
but tat code i write seem can not read...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 21
Reputation: ricnyx is an unknown quantity at this point 
Solved Threads: 0
ricnyx ricnyx is offline Offline
Newbie Poster

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

 
0
  #8
Nov 26th, 2007
sorry...the data example should wirte like this :
today 1000
yesterday 1000
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: jaux is an unknown quantity at this point 
Solved Threads: 2
jaux's Avatar
jaux jaux is offline Offline
Newbie Poster

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

 
0
  #9
Nov 27th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 21
Reputation: ricnyx is an unknown quantity at this point 
Solved Threads: 0
ricnyx ricnyx is offline Offline
Newbie Poster

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

 
0
  #10
Nov 27th, 2007
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 .... ^^
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC