Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "RpnCalculator.h"
- using namespace std;
- void input();
- int main(void) {
- cout << endl << "Reverse Polish Notation Calculator." << endl << endl <<
- "Please enter some values to compute followed by the return key or press Q to quit." << endl;
- input();
- cout << "Goodbye.";
- return 0;
- }
- void input() {
- RpnCalculator *c = new RpnCalculator();
- int i_value = 0;
- char input = '\0';
- bool play = true;
- cout << "(Acceptable operators: + - * /)" << endl;
- do {
- cout << " --> ";
- // Takes a value from the user and assigns it to 'input'.
- cin.sync();
- input = cin.get();
- /* Checking that input.
- * If it's an operator it performs the operation and prints the result.
- * If it's a numerical value, the char is cast to an int and passed to the _operands vector using push().
- */
- switch (input) {
- case '+' :
- c->add();
- cout << endl << " Result: " << c->answer() << endl;
- break;
- case '-' :
- c->subtract();
- cout << endl << " Result: " << c->answer() << endl;
- break;
- case '*' :
- c->multiply();
- cout << endl << " Result: " << c->answer() << endl;
- break;
- case '/' :
- c->divide();
- cout << endl << " Result: " << c->answer() << endl;
- break;
- case '0' :
- case '1' :
- case '2' :
- case '3' :
- case '4' :
- case '5' :
- case '6' :
- case '7' :
- case '8' :
- case '9' :
- cout << input << endl;
- i_value = static_cast<int>(input);
- c->push(i_value);
- case 'q' :
- case 'Q' :
- play = false;
- break;
- default :
- cout << " Please enter an operator, a number, or Q to quit " <<endl;
- break;
- }
- } while (play);
- delete c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement