- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int computer,player,win = 0,lost=0;
- srand(time(NULL));
- string name [4]= {"剪子","石子","布","over"};
- cout<<"出拳(1)剪子(2)石子(3)布(4)over";
- cin>>player;
- if(player == 1||player == 2||player == 3)
- {
- computer = rand()%3+1;
- cout<<"你出"<<name[player-1];
- cout<<endl;
- cout<<"電腦出"<<name[computer-1];
- if(player == 1)
- {
- if(computer == 1)
- cout<<"Again!";
- if(computer == 2)
- {
- cout<<"You Lost!";
- lost+=1;
- }
- if(computer == 3)
- {
- cout<<"You Win!";
- win+=1;
- }
- }
- if(player == 2)
- {
- if(computer == 2)
- cout<<"Again!";
- if(computer == 3)
- {
- cout<<"You Lost!";
- lost+=1;
- }
- if(computer == 1)
- {
- cout<<"You Win!";
- win+=1;
- }
- }
- if(player == 3)
- {
- if(computer == 3)
- cout<<"Again!";
- if(computer == 1)
- {
- cout<<"You Lost!";
- lost+=1;
- }
- if(computer == 2)
- {
- cout<<"You Win!";
- win+=1;
- }
- }
- if(player == 4)
- {
- cout<<"win:"<<win<<" lost:"<<lost<<endl;
- }
- cout<<endl;
- }
-
- else
- cout<<"You are beach"<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |