Project Description
Background
Reverse Polish Notation is simply a way of denoting an operator after the number. So instead of saying 5 + 4
, we would say 5 4 +
. More info on Reverse Polish Notation can be here. While they have a little bit of a learning curve, their big advantage is that they allow the user to work left to right across the equation without having to do any pre-work for parenthesis.
Functionally, the RPN calculator works off the principle of a stack. Anytime you hit an operator such as +
, -
, *
, or /
, the calculator performs that operation on the first two members in the stack and then places the result back in on top of the stack. Since a stack is last in first out, if you enter 6 then 5 then 4, your stack would look like this:
4 -- Top
5
6
Now if you hit the plus sign, the calculator will take the first two numbers in the stack (4 and 5) and add them, then put the result back on top of the stack. Your stack will now look like this:
9 -- Top
6
Next, if you hit the multiplication sign, it will multiply 9 times 6 and put 54 back in the stack.
Your Task
In this project, you will create an RPN Calculator! It only needs to worry about the 4 basic operations (+
, -
, *
, and /
), and it should continue to loop until the user enters exit.