- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- cout<<"猜拳遊戲"<<endl;
- srand(time(NULL));
- int player,computer;
- int win=0,lose=0,tie=0;
- string name[3]={"剪刀","石頭","布"};
- cout<<"請出拳! (1)剪刀(2)石頭(3)布(0)結束 :";
- if(player==0)
- goto end;
- cin>>player;
- computer=rand()%3+1;
- cout<<"你出"<<name[player-1]<<endl;
- cout<<"電腦出"<<name[computer-1]<<endl;
- if(player==computer)
- {
- cout<<"平手!!!"<<endl;
- tie+=1;
- }
- if((player==1&&computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
- {
- cout<<"你贏了!!!"<<endl;
- win+=1;
- }
- else
- {
- cout<<"你輸了!!!"<<endl;
- lose+=1;
- }
- end:
- {
- cout<<"戰果統計"<<endl;
- cout<<"贏了"<<win<<"次"<<"輸了"<<lose<<"次"<<"平手了"<<tie<<"次"<<endl<<
-
-
- }
- system("pause");
- return 0;
- }
複製代碼 |