Help with calculator code

I have recently starting taking a c++ class and I have a question about creating a RPN calculator. We have not gone over stacks in class at all (they aren't even in my textbook) and my teacher has given us an assignment to create a RPN calculator in a loop. I understand that the order in a RPN calculator goes like this 5 5 * however when I search for help on this subject EVERYTHING comes up with stacks included. Is it possible to create a RPN calculator without using stack? I went ahead and created a basic calculator on a loop and have that code below just in case I cannot get the RPN to work before it is due so I can at least get some points for the effort

[code]

#include <iostream>

using namespace std;

int main(int argc, char** argv) {

float num1, num2, answer;
char operation, again;
//starts loop for calculator with basic instructions for user input
do
{
cout << "Calculator" << endl;
cout << endl;
cout << "Please enter first number: ";
cin >> num1;
cout << "Please enter second number: ";
cin >> num2;
cout << "Please enter operation (+, -, *, /): ";
cin >> operation;
//sets up the equation for each operation
switch (operation)
{
case '+':
answer = num1 + num2;
break;

case '-':
answer = num1 - num2;
break;

case '*':
answer = num1 * num2;
break;

case '/':
answer = num1 / num2;
break;

default:
cout << "Invalid entry." << endl;
}
//shows equation and answer based on all that the user has entered
cout << num1 << " " << operation << " " << num2 << "= " << answer;
cout << endl;
//gives user an option for another calculation
cout << "Would you like to do another calculation, Y or N? " << endl;
cin >> again;
cout << endl;
}
//if user chooses Y, the loop will run again
while (again=='Y');
//if user chooses N, the program will end
while(again=='N')
{
break;
}


return 0;
}
Last edited on
you need a stack friendo, it isn't possible otherwise.
Thank you! That's what I figured but I wanted to make sure. Guess I'll go look at stack tutorials. :)
Topic archived. No new replies allowed.