If you would use code tags when you post, it would be much easier to point where in the code to make changes.
After
cin>>operation;
put
1 2 3 4
|
if ((operation!='+')||(operation!='-')||(operation!='*')||(operation!='/'))
{
//output here a message and exit program
}
| |
Then you don't need the else if. By the way, if you select '+' for example, your program executes that option, then it checks if the operator is '-' (which is useless at this point, since you selected +), then does the same thing with *. When it tries to do that with '/', it does not satisfy the condition, so it will go to the else statement, and say that you have an invalid operation. You should use
else if before -,*,/. Like I said, you would like to deal with other cases before the second number, so you don't need the last
else
A nice solution would be for you to use a while loop around the input for the operation, so you repeat that until a valid operator is entered