- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- cout<<"*****猜拳3缺1*****"<<endl;
- int P1,com,win=0,lose=0,draw=0;
- re:
- srand(time(NULL));
- string name[3]={"剪刀","石頭","布",};
- cout<<"請出拳!!! <1>剪刀<2>石頭<3>布<0>結束 :";
- cin>>P1;
- if(P1==0)
- {
- goto final;
- }else if(P1>=1 && P1<=3)
- {
- cout<<"你出"<<name[P1-1]<<endl;
- com=rand()%3+1;
- cout<<"電腦出"<<name[com-1]<<endl;
- if(P1==com)
- {
- draw++;
- cout<<"你們平手"<<endl;
- }else if(P1==1 && com==3 || P1==2 && com==1 || P1==3 && com==2)
- {
- win++;
- cout<<"你贏了!!!!!!!!!!教師節快樂!!!!!!!!!!!!!!!!!!";
- }else
- {
- lose++;
- cout<<"你輸了!!!!!!!!!!光棍節快樂!!!!!!!!!!!!!!! 87"<<endl;
- }
- cout<<endl<<endl;
- goto re;
- }else
- {
- cout<<"輸入錯誤!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
- goto re;
- }
-
- final:
- cout<<"*****結果*****"<<endl;
- cout<<"你贏了"<<win<<"場,輸了"<<lose<<"場,平手"<<draw<<"場"<<endl;
-
- system ("pause");
- return 0;
- }
複製代碼 |