嘿,我正在为我的 C++ 编程课程制作一个 Switch 选择菜单。我已经设法让我的菜单工作,但我不知道如何在我制作的菜单中的退出选择上停止程序。
我的代码是
#include <iostream>
using namespace std;
int main()
{
char selection;
do
{
cout << " IHCC Computer Science Registration Menu\n";
cout << " ====================================\n";
cout << " 1. Welcome to Computer Programming In C++\n";
cout << " 2. Welcome to Java Programming\n";
cout << " 3. Welcome to Android Programming\n";
cout << " 4. Welcome to iOS Programming\n";
cout << "\n";
cout << " 5. Exit\n";
cout << " ====================================\n";
cout << " Enter your selection: ";
cin >> selection;
cout << endl;
switch (selection)
{
case '1':
cout << "Computer Programming In C++\n";
cout << "\n";
break;
case '2':
cout << "Java Programming\n";
cout << "\n";
break;
case '3':
cout << "Android Programming\n" ;
cout << "\n";
break;
case '4':
cout << "iOS Programming\n";
cout << "\n";
break;
case '5':
cout << "Goodbye.\n";
break;
default: cout <<selection << "is not a valid menu item.\n";
cout << endl;
}
}while (selection != 0 );
return 0;
}