- #include <iostream>
- using namespace std;
- int main()
- {
- int x=3,y=5,z=7;
- int p;
- char ch;
- cout<<x<<" "<<y<<" "<<z<<endl;
- do{
- cout<<"选择豆堆a,b或c"<<endl;
- cin>>ch;
- switch(ch)
- {
- case'a':
- {
- cout<<"请输入想要拿去的豆子"<<endl;
- cin>>p;
- x-=p;
- cout<<x<<" "<<y<<" "<<z<<endl;
- break;
- }
- case'b':
- {
- cout<<"请输入想要拿去的豆子"<<endl;
- cin>>p;
- y-=p;
- cout<<x<<" "<<y<<" "<<z<<endl;
- break;
- }
- case'c':
- {
- cout<<"请输入想要拿去的豆子"<<endl;
- cin>>p;
- z-=p;
- cout<<x<<" "<<y<<" "<<z<<endl;
- break;
- }
- default:cout<<"SDF"<<endl;
- }
- }while(x!=0||y!=0||z!=0);
- cout<<"你输了"<<endl;
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2110201410745.html
来源: http://www.codesnippet.cn/detail/2110201410745.html