case 1:
where did fixed_expenses come from?
what's with three ifstream objects (fin, fin1 and fin2????
Don't use eof() in a loop conditional. It's bound to trip you up sooner or later.
Doesn't it make more sense to give income a numerical value and name a string value?
The basic approach here seems to be to try to read through the file twice, once with each loop, which is illogical.
case 2:
declare name to be a string and income1 to be of type double.
make the while conditional just fin1 >> name.
Drop these two lines:
cout << income;
fin1.get (income);
if sum is declared type double and initialized to zero before the loop starts, it should work. Basically you read in the first token in the line and ignore whatever it is. Then, assuming there was a first token, you read in the second token, and add it's value to sum. When you reach the end of the file and fin1 tries to read EOF into name, then the stream will fail, which will cause a value of zero to return, which will stop the loop.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Offline 2,253 posts
since Jul 2005