本帖最後由 張郁偵 於 2014-3-15 17:08 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int player,computer,draw=0,win=0,lose=0;
- srand(time(NULL));
- string name[3]={"剪刀","石頭","布"};
- cout<<"※※猜拳遊戲※※"<<endl;
- start:
- cout<<"請出拳!(1)剪刀(2)石頭(3)布(0)結束"<<endl;
- cin>>player;
- if(player==0)
- goto end;
- else if(player>=1 && player<=3)
- {
- computer=rand()%3+1;
- cout<<"你出"<<name[player-1]<<endl;
- cout<<"電腦出"<<name[computer-1]<<endl;
-
- if(player==computer)
- {
- cout<<"平手"<<endl;
- draw++;
- }else if((player==1 && computer==3)||(player==2 && computer==1)||(player==3 && computer==2))
- {
- cout<<"你贏了"<<endl;
- win++;
- }else if((player==3 && computer==1)||(player==1 && computer==2)||(player==2 && computer==3))
- {
- cout<<"電腦贏了"<<endl;
- lose++;
- }
- goto start;
- }else
- {
- cout<<"輸入錯誤!"<<endl;
- goto start;
- }
- end:
- cout<<"※※戰果統計※※"<<endl;
- cout<<"總共贏了"<<win<<"次,"<<"輸了"<<lose<<"次,"<<"平手"<<draw<<"次,"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |