I am now doing a RPN calculator. I just trying doing the first part where I want user to key in at least 2 numbers before the program asked if the user want to enter a operator such as (+, -, *, /) or another number for doing the RPN calculator.Now, i not doing the operator yet but just want the user to key in the number, push it before printing the number using pop in my code. -999 is to end the program to print the number with pop using <stack>.

Now, i got a problem, let say we need to have at least 2 numbers before it is possible to do a RPN calculator. So, I had to include 2 variables. After initialise it and user enter 2 of the numbers, I want to pop 2 of the numbers and print it using pop with <stack>. The problem is there is no problem if I just used only one variable, but instead I am using 2 variables. Because we need to have at least 2 numbers before possible to do RPN calculator. How should I solve this.

I am thinking of doing it with array but you see, after getting 2 numbers , i want the user to either select another number or operator, so it likes it is not possible using array. So i am using only variables and repeat the whole process using while/for loops.

Anyway, regarding the RPN calculator, is it true that if you had n numbers. n represent the amount of operand or simply called the numbers using algebra. I need to have at least (n - 1) operator?

Example, if you had 5 operands/numbers, you need at least 4 operators such as (+ , -, / , *) and not like only 3 or less operators or more than 4 operators.

Please help me how should I do it or any suggestions about it. Many thanks. My code did shown 2 variables. But got messed up if I try to do it with 2 variables. So i only done using 1 variable and worked perfectly.

I will quote from wiki the solution :
"Interpreters of Reverse Polish notation are often stack-based; that is, operands are pushed onto a stack, and when an operation is performed, its operands are popped from a stack and its result pushed back on. So the value of postfix expression is on the top of the stack. Stacks, and therefore RPN, have the advantage of being easy to implement and very fast."Reverse Polish notation - Wikipedia, the free encyclopedia
If you have more question then feel free to ask..

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Need some hints, lets said if the user gives more than 3 numbers and using more than 1 operator(+, -, /, *). for the program to work, do I need to declare an array integer, or using while/for loops, or declare indiduval variables(which I think not possible). How about the operands. The user can input 2, 3, 4, 5, 6 numbers with different amount of operators, should I use an char array.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

yes, it is completely different from the normal calculations. All the numbers would followed first before the operators unlike the normal calculation.
Example: 3 / 5+ 3 and 5 would added.
Example: 5 6 + 3 - 2 5 would be push into stack first followed by 6 which is also push into the stack. If there are a operator, the first 2 numbers would be pop and do the calculations.

And i also need to do character RPN. Is it possible to do it such as XYZ XY- which gives Z as the solution using stack. I heard I need operator overloading for character RPN?

5 would be push into stack first followed by 6 which is also push into the stack. If there are a operator, the first 2 numbers would be pop and do the calculations.

Okay. Notice that you did not talk about an array. You need to be clear on what you are trying to do. Why reach for an array before you are sure you need one?

Originally Posted by evildotaing

And i also need to do character RPN. Is it possible to do it such as XYZ XY- which gives Z as the solution using stack.

I have never heard of "character RPN". Your example is unclear since I have no clue what is "XYZ XY-" and I don't see why it would give Z as the solution.

Originally Posted by evildotaing

I heard I need operator overloading for character RPN?

After having read your thread on mastering C++, and now hearing your repeated talk of operator overloading, I am starting to suspect that you are infected with C++ featuritis. The symptom is a compulsion to use every feature of C++ that the sufferer knows, just because the sufferer can

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.