I'm having trouble programming an infix calculator. I take the input from the user as a character array and output the postfix expression as a char array also. What I'm having problems with is doing the actual calculation of the numbers in the postfix. For example, I put in 1+7 and I get the ascii equivalent of 'h' (104). I tried casting the numbers into int to do the operation, but it just does ascii addition.
Help With Infix Calculator
Page 1 of 1
Help With Infix Calculator Problem calculating numbers
#2
Posted 12 February 2006 - 03:25 PM
If you want to change a single digit into a number, you can subtract '0'. Let's say you have '6', which is ASCII code 54. Subtract '0', which is ASCII code 48 and you get 6. That doesn't work for values larger than 9 though, because the conversion is more involved when there are multiple digits. For that, you'll want to break the string up into tokens and use someone like atoi who does the hard work for you.
Page 1 of 1

Start a new topic
Add Reply





MultiQuote
| 


