- #include<iostream>
- using namespace std;
- int main()
- {
- int computer;
- int player;
- start:
- cout<<"輸入你想出的拳:(1=剪刀; 2=石頭; 3=布) ";
- cin>>player;
- srand(time(NULL));
- computer=rand()%3+1;
- if(computer==1)
- {
- if(player==1)
- {
- cout<<"電腦出剪刀,你也出剪刀,平手!";
- }else if(player==2)
- {
- cout<<"電腦出剪刀,你出石頭,你贏了!";
- }else if(player==3)
- {
- cout<<"電腦出剪刀,你出布,你輸了!";
- }else
- {
- cout<<"不要亂打,小心我打你!";
- }
-
- }else if(computer==2)
- {
- if(player==1)
- {
- cout<<"電腦出石頭,你出剪刀,你輸了!";
- }else if(player==2)
- {
- cout<<"電腦出石頭,你也出石頭,平手!";
- }else if(player==3)
- {
- cout<<"電腦出石頭,你出布,你贏了!";
- }else
- {
- cout<<"不要亂打,小心我打你!";
- }
-
- }else if(computer==3)
- {
- if(player==1)
- {
- cout<<"電腦出布,你出剪刀,你贏了!";
- }else if(player==2)
- {
- cout<<"電腦出布,你出石頭,你輸了!";
- }else if(player==3)
- {
- cout<<"電腦出布,你也出布,平手!";
- }else
- {
- cout<<"不要亂打,小心我打你!";
- }
- }
- cout<<endl<<endl;
- goto start;
- system("pause");
- return 0;
- }
複製代碼 |