33,311
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
void menu();
int main()
{
menu();
char ch;
cin.get(ch);
while (ch != EOF)
{
while (ch!='c' && ch!='p' && ch!='t' && ch!='g')
{
cout << "Please enter a c,p,t, or g: ";
cin.get(ch);
}
switch(ch)
{
case 'c': cout << "A maple is a carnivore.\n";
break;
case 'p': cout << "A maple is a pianist. \n";
break;
case 't': cout << "A maple is a tree. \n";
break;
case 'g': cout << "A maple is a game. \n";
break;
}
cin.get(ch);
}
return 0;
}
void menu()
{
cout << "Please enter one of the following choices: \n";
cout << "c)carnivore\t" << "p)pianist\n";
cout << "t)tree\t" << "g)game\n";
}