As I was looking through my past questions, I noticed my really old calculator question (here and here). Considering it looked like a huge mess, I decided to rewrite it. Coincidentally, the April 2015 Community Challenge was to implement a simple calculator. It might be a bit late, but here it is: The logic here is fairly simple: In addition (or subtraction or multiplication or whatever), you go from left to right: is essentially the same as: but with , you have to go from right to left.