您的位置:首页 > 编程语言 > C语言/C++

C++primer plus第六版课后编程练习答案6.3

2015-11-26 15:51 417 查看
#include<iostream>
#include<cctype>
#include<cstdlib>//support for exit(),atoi()
#include<string>
#include<fstream>//文件I/O
#include<sstream>//stringstream转换各种数据格式
using namespace std;

void main()
{
cout<<"Please enter one of the following choices:"<<endl;
cout<<"c) carnivore \t p) pianist"<<endl;
cout<<"t) tree \t g) game"<<endl;

char ch;
int n=1;
while(n)
{
cin>>ch;
switch(ch)
{
case 'c':cout<<"carnivore"<<endl;n=0;break;
case 'p':cout<<"pianist"<<endl;n=0;break;
case 't':cout<<"tree"<<endl;n=0;break;
case 'g':cout<<"game"<<endl;n=0;break;
default:cout<<"Please enter a c, p, t, or g:";
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: