For class we are supposed to make a Menu using a while loop and a switch statement. I have done the given code, but the output keeps giving me an extra menuT. How do I fix this and make it look like the expected output?
#include <iostream>
usingnamespace std;
int main()
{
string menuT="\n==== Menu Top ====\nA\tGoTo Menu A\nB\tGoTo Menu B\nE\tExit: ";
string menuA="\n\t==== Menu A ====\n\tA\tDo Action A\n\tB\tDo Action B\n\tE\tExit: ";
string menuB="\n\t==== Menu B ====\n\tA\tDo Action A\n\tB\tDo Action B\n\tE\tExit: ";
string mexit="Exit Menu";
string badi ="Bad Input";
string dida ="\tDid A";
string didb ="\tDid B";
char c;
while(c == 'a' || 'b' || 'e')
{
cout << menuT;
cin >> c;
switch (c)
{
case'a':
cout << menuA;
cin >> c;
if (c == 'a')
cout << dida << menuA;
elseif (c == 'b')
cout << didb << menuA;
elseif (c == 'e')
cout << mexit << menuT;
else
cout << badi;
break;
case'b':
cout << menuB;
cin >> c;
if (c == 'b')
cout << didb << menuB;
elseif (c == 'a')
cout << dida << menuB;
elseif (c == 'e')
cout << mexit << menuT;
else
cout << badi;
break;
default :
cout << badi;
}
}
return 0;
Here is the expected output:
==== Menu Top ====
A GoTo Menu A
B GoTo Menu B
E Exit: 2
Bad Input
==== Menu Top ====
A GoTo Menu A
B GoTo Menu B
E Exit: a
==== Menu A ====
A Do Action A
B Do Action B
E Exit: 2
Bad Input
==== Menu A ====
A Do Action A
B Do Action B
E Exit: e
Exit Menu
==== Menu Top ====
A GoTo Menu A
B GoTo Menu B
E Exit: b
==== Menu B ====
A Do Action A
B Do Action B
E Exit: 2
Bad Input
==== Menu B ====
A Do Action A
B Do Action B
E Exit: a
Did A
==== Menu B ====
A Do Action A
B Do Action B
E Exit: b
Did B
==== Menu B ====
A Do Action A
B Do Action B
E Exit: e
Exit Menu
==== Menu Top ====
A GoTo Menu A
B GoTo Menu B
E Exit: e
Exit Menu