Hello, this is my first post. I am making a calculator using stacks. curpos is the the variable of the top of the stack that is initially set to -1. Every time I call the push function, curpos will increment by 1. Then the function will store in the number the user entered. The pop function will decrease by 1 and "pop" the number of curpos out. These 2 functions work fine. The part where I don't get is my add function. The add function is from the RPN class, which is an inherited class of the Stack class. When I call my add function, it will go to the "else" part and displays an error. It goes to else because apparently my curpos is -1(I checked with cout << curpos). However, i am sure that i set my curpos to 1 after my program prompted the user to enter 2 numbers. Since I do not get why my curpos is set back to -1 when my push and pop functions work perfectly, is there something wrong with my inherited class?
while(true) { //Loop perpetuates until user chooses to quit
cout << "Type in anykey except q to continue" << endl;
cin >> input;
if (input[0] == 'q')
break;
cout << "Type in the number, the operator, and the number" << endl;
cin >> num1 >> op >> num2;
cin.ignore();
stk.push(num1);
stk.push(num2);
switch(op[0]) {
case '+': calc.add();
break;
case '-': calc.subtract();
break;
case '*': calc.multiply();
break;
case '/': calc.divide();
break;
default: cout << "Unacceptable input" << endl;
break;
}
stk.show();
}
}