c++ primer plus 习题6.3(switch)

来源:互联网 发布:茵曼淘宝网店 编辑:程序博客网 时间:2024/06/09 23:05
#include<iostream>using namespace std;int main(){cout<<"please enter one of the following choices:\n";cout<<"c) carrnivore"<<"\t"<<"p) pinist\n";cout<<"t) tree"<<"\t"<<"g) game\n";char choice;cin>>choice;while(choice!='c'&&choice!='p'&&choice!='t'&&choice!='g'){cout<<"please enter a c, p, t, or g;";cin>>choice;cout<<"\n";}//while(choice=='c'||choice=='p'||choice=='t'||choice=='p'){switch(choice){case 'c':cout<<"A maple is a carrnovore\n";break;case 'p':cout<<"A maple is a pinist\n";break;case 't':cout<<"A maple is a tree\n";break;case 'g':cout<<"A maple is a game\n";break;}return 0;}

0 0
原创粉丝点击