I've been working on some simple programs using the switch statement for c++ programming class and am always having the same problem with nested switches. I am trying to create a menu like system in the console to give the users choices.
Obviously, it will first prompt you for a choice between algebra or geometry. If you choose algebra, it gives you another set of choices. The problem is that once you choose between the nested algebra choices, the program also goes ahead and prints out "geometry" from case 'g' no matter what you choose. How can I make the program not do this and simply return to the first menu?Code:char mc; char ac; cout << "which choice do you want? (a)lgebra, (g)eometry?"; cin >> mc; switch (mc) { case 'a': cout << "what operation you want to perform? a(d)dition, d(i)vision, (s)ubtraction?"; cin >> ac; switch (ac) { case 'd': cout << "addition"<<endl; break; case 'i': cout << "division"<<endl; break; case 's': cout << "subtraction"<<endl; break; } case 'g': cout << "geometry"; break; } return 0; }