问题描述:编写一个简单的菜单驱动程序,如下所示:
please enter one of the following choice:
c)carnivore p)pianist
t)tree g)game
please enter a,c,p,t,or g:q
please enter a,c,p,t,or g:t
a maple is a tree
解决思路:
1.输出上述菜单程序
2.读取用户得输入,判断是否为所需字母
3.不是就再次提醒用户
4.如果是那么输出这句话a maple is a tree
代码:
#include <iostream>
using namespace std;
int main()
{
char a;
printf("please enter one of the following choice:\n");
printf("c)carnivore p)pianist\n");
printf("t)tree g)game\n");
while (1)
{
printf("please enter a,c,p,t,or g:");
cin >> a;
if (a == 'c' || a == 'p' || a == 't' || a == 'g')
{
printf("a maple is a tree");
break;
}
}
return 0;
}