Let's examine your logic in small pieces, right?
Code:
getline(cin,sequation);
equation<<sequation;
You read in the equation.
Code:
while(!equation.end)
{
You loop while the logical negation of the ios::end (a constant flag indicating "seek from end" in the seekg and seekp calls) is true - this is never the case. Error number one. You want while(equation).
You set the subresult for multiplicative operations to 0.
Code:
while(operation!='+'||operation!='-')
{
You loop while the operation is not '+' or not '-'. This is trivially always true, since it would only be false if operation was both '+' and '-', which is impossible.
Also, because operation is only given a value inside this loop, it will be uninitialized the first time around. Undefined behaviour.
Code:
equation>>number>>operation;
You parse a single number and operation.
Code:
switch(operation)
{
case '*':
nomial*=number;
break;
case '/':
if(number!=0)
nomial/=number;
break;
}
If it's multiplication or division, you perform it on the subresult.
Of course, since the subresult starts out as 0, any multiplicative operation yields 0 again, so this is all a big no-op. Error number 4.
Oh, and you should check for division by zero, since the language doesn't do it for you.
Code:
}
switch(operation)
{
case '+':
result+=nomial;
break;
case '-':
result-=nomial;
break;
}
Now, if the loop ends (i.e. operation is '+' or '-' if we correct your code for intention), you perform the additive operation using the subresult. Incidently, this means you throw away the number you just parsed.
Interestingly, since operation keeps its value, which must be '+' or '-' at this point, the inner loop (which is the only place operation might change its value) is never entered again. Oops.
}
cout<<result<<endl;[/code]
Finally, you write the result.
OK, now let's look at the big picture. Unfortunately, the whole logic is completely broken. I'll look at what the code does for some test strings, assuming a few small things are corrected. I'll post the code again with numbered lines for easy reference.
Code:
1 getline(cin,sequation);
2 equation<<sequation;
3 while(equation)
4 {
5 nomial=0;
6 while(operation!='+'&&operation!='-')
7 {
8 equation>>number>>operation;
9 switch(operation)
10 {
11 case '*':
12 nomial*=number;
13 break;
14 case '/':
15 if(number!=0)
16 nomial/=number;
17 break;
18 }
19 }
20 switch(operation)
21 {
22 case '+':
23 result+=nomial;
24 break;
25 case '-':
26 result-=nomial;
27 break;
28 }
29 }
30 cout<<result<<endl;
Let's start simple:
1 + 2
OK, line 8 is interesting.
nomial = 0
number = 1
operation = +
The switch on line 9 skips completely. The while on line 6 is terminated.
We get to line 20. nomial (0) is added to result (0), yielding 0.
Restart. The while loop on line 6 is skipped, since operation is still '+'.
We get to line 20. nomial (0) is added to result (0), yielding 0.
And so on, forever.
Another simple input:
1 * 2
After line 8, we have:
nomial = 0
number = 1
operation = *
The switch on line 9 gets something this time. nomial (0) is multiplied by number (1), yielding 0.
Restart the while loop. Line 8 executes again.
nomial = 0
number = 2
operation cannot be parsed for lack of input and retains the value *.
equation goes into end of file and failure state.
The switch on line 9 hits a target. nomial (0) is multiplied by number (2), yielding 0.
Restart the while loop. Line 8 executes again.
Since equation is not in good state, it doesn't read anything. All values remain unchanged.
Oops, looks like another infinite loop.
So, simply put, if line 3 hadn't stopped you from ever parsing the equations, your program would have simply hung in one endless loop or another.