c++ primer plus6.11第三题
编写一个菜单驱动程序雏形。
#include<iostream>
using namespace std;
#include<string>
int main()
{
cout << "please enter one of the following choices" << endl;
cout << "c) carnivore" << "\tp) pianist" << endl;
cout << "t) tree" << "\t"<<"\tg) game" << endl;
char ch;
cout << "please enter a c, p, t or g:" << endl;
while (1)
{
cin >> ch;
switch (ch)
{
case 'c':
{
cout << "a maple is a carnivore" << endl;
system("pause");
exit(0);
}
case 'p':
{
cout << "a maple is a pianist" << endl;
system("pause");
exit(0);
}
case 't':
{
cout << "a maple is a tree" << endl;
system("pause");
exit(0);
}
case 'g':
{
cout << "a maple is a game" << endl;
system("pause");
exit(0);
}
default:
{
cout << "please enter a c, p, t or g:" << endl;
}
}
}
system("pause");
return 0;
}