Reading the next line of an input file...
Nov 8, 2011 at 9:07pm UTC
This is a homework problem, but I've exhausted all my other resources and I'm turning to you for help!!
I've been given an input file with a series of simple expressions that looks like this:
1 2 3 4 5 6 7 8
123.5 + 59.3
198.7 / -26
125 $ 28
89.3 * 2.5
178.9 - 326.8
198.7 / 0
34.0 ? 10
236 % 45
The program terminates once it hits the expression with the "?" operator. I've written the whole program, but I can't figure out how to read the input file. Heres what I have so far.... but the problem is that it reads the first line over and over and over again.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
//readExpression()
fin >> operand1 >> function >> operand2;
while (function != '?' )
{
//echoExpression()
fout << operand1 << function << operand2;
//evaulateExpression()
switch (function)
{
case '+' : solution=operand1+operand2;
break ;
case '-' : solution=operand1-operand2;
break ;
case '*' : solution=operand1*operand2;
break ;
case '/' : if (operand2==0)
{
fout <<operand1<<function<<operand2
<<" Division by zero produces an undefined result." ;
return 2;
}
else solution=operand1/operand2;
break ;
default :
fout << operand1 << function << operand2
<<" Encountered an unknown operator." ;
return 3;
break ;
}
fin >> operand1 >> function >> operand2;
}
So I ask: how do I get it to go to the next, and next, and next line?
Topic archived. No new replies allowed.