驱动菜单的雏形6/2/04 9:58AM
驱动菜单的雏形
#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
char r;
cout << "please enter one of the following choices:/n";
cout << "c) carnirore" << " " << " " << "p) pianist/n";
cout << "t) tree" << " " << " " << "g) game/n";
cout << "please enter a c,p,t,or g:";
while(cin >> r)
{
r = tolower(r);
if(r == 'c'|| r == 'p' || r == 't' || r == 'g')
{switch (r)
{
case 'c': cout <<"a maple is a carnirore/n";
cout << "please enter a c,p,t,or g:";
break;
case 'p': cout <<"a maple is a pianist/n";
cout << "please enter a c,p,t,or g:";
break;
case 't': cout <<"a maple is a tree/n";
cout << "please enter a c,p,t,or g:";
break;
case 'g': cout <<"a maple is a game/n";
cout << "please enter a c,p,t,or g:";
break;
}
}
else
cout << "please enter a c,p,t,or g:";
}
return 0;
}
博客展示了驱动菜单雏形的代码。代码使用 C++ 编写,通过 `while` 循环和 `switch` 语句,根据用户输入的 `c`、`p`、`t`、`g` 选项输出不同信息,若输入无效则提示重新输入。

被折叠的 条评论
为什么被折叠?



