School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,144 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,813 people online right now. Registration is fast and FREE... Join Now!



Help With Infix Calculator

Help With Infix Calculator Problem calculating numbers Rate Topic: -----

#1 wingz198  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 55
  • Joined: 14-October 05


Dream Kudos: 0

Posted 12 February 2006 - 02:36 PM

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.
Was This Post Helpful? 0
  • +
  • -


#2 Voodoo Doll  Icon User is offline

  • D.I.C Head
  • Icon
  • Group: Expert
  • Posts: 107
  • Joined: 24-January 06


Dream Kudos: 175

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. :)
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month