I have an assignment where I have to create a program in which I use Stacks to evaluate post-fix mathematical expressions. I have to create the Stacks myself instead of using them from a library in order to understand them better. The only problem is I want to have the user interact with a menu of multiple functions, and the do-while loop in FUN_COMMAND() won't work, so the user can only do one thing from the menu (as the loop runs once). I have the code below. Is there something I'm missing or need to change in the loop itself or is it outside the loop? *Note* All the variables before the main are global to the other functions which I havent included.
int main ()
{
cout << "Would you like to use an expression from a file?" << endl << "*Note* A postfix expression from file will be automatically evaluated" << endl << "(y/n): ";
cin >> YesNo; cout << endl;
do
{
cout << "Type a command number..Scroll up to view commands if needed" << endl;
cout << "*Note* An integer and string stack must be created to use other commands" << endl;
cout << "Command Number: "; cin >> command;
if (command == '1')
{
CREATE_S ();
}
else if (command == '2')
{
CREATES_S ();
}
else if (command == '3')
{
PUSH_X_S ();
}
else if (command == '4')
{
POP_S ();
}
else if (command == '5')
{
EMPTY_S ();
}
else if (command == '6')
{
EVAL_X_S ();
}
else if (command == '7')
{
EVALS_S1_S2 ();
}
else if (command == '8')
{
DISPLAY_S ();
}
else if (command == '9')
{
cout << "Exiting.." << endl;
}
else
{cout << "Improper input.." << endl;}
} while (command =! '9');
}
void MENU ()
{
cout << endl;
cout << " Command Menu" << endl;
cout << "-----------------------------" << endl;
cout << "Command Function" << endl;
cout << "-----------------------------" << endl;
cout << "1.CREATE S........creates empty integer stack" << endl;
cout << "2.CREATES S.......creates empty string stack" << endl;
cout << "3.PUSH X S........pushes element x onto stack" << endl;
cout << "4.POP S..........pops top element from stack" << endl;
cout << "5.EMPTY S.........checks if stack is empty" << endl;
cout << "6.EVAL X S........evaluates string x using integer stack and displays result" << endl;
cout << "7.EVALS S1 S2.....pops postfix from string stack and evaluates integer stack displaying results" << endl;
cout << "8.DISPLAY S.......displays contents of stack, top to bottom" << endl;
cout << "9.QUIT............displays contents of existing stacks and terminates program" << endl;
cout << "------------------------------------------------------------------------------" << endl;
}
//After this are all the other functions which (hopefully) are arbitrary to the problem