Just an idea to show how you might avoid repeating code - here is some psuedo code:
1 2 3 4 5
|
//1 get a number
//2 get an operator
//2.1 check it's a valid operator
//3 get a number
//4 calculate answer
|
This shows which parts could be functions, items 1 & 3 are the same, so you could make it a function that is called twice, or you can combine them by getting both numbers like you have, but make it a function.
Always keep a look out for repeated code - it means you need a function or a loop.
You can make use of a switch statement with a default clause for the IsOperator function, and to do the calculation.
Also be aware of what happens with integer division, not only do you have to check for division by zero, but realise that 2 / 5 is zero because of truncation.
When checking for equality with zero for a float or double, don't use the == operator, just check whether the absolute value is less than some arbitrary precision like 0.001 say. This is because FP numbers are stored as binary fractions, and cannot represent every real number. To see how things can go wrong print out the value of double 0.1 to 16 decimal places.
HTH