- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int player,computer;
- cout<<"請出拳(1)剪刀(2)石頭(3)布";
- cin>>player;
-
- if (player==1)
- {cout<<"你出剪刀"<<endl;}
-
- else if (player==2)
- {cout<<"你出石頭"<<endl;}
-
- else {cout<<"你出布"<<endl;}
-
- srand(time(NULL));
- computer=rand()%3+1;
- cout<<computer<<endl;
- if (player==computer)
- {cout<<"平手"<<endl;}
- else if((player==3 && computer==1)||
- (player==2 && computer==3)||
- (player==1 && computer==2))
-
- {cout<<"你贏了"<<endl;}
-
- else {cout<<"你輸了"<<endl;}
-
- goto re;
- system("pause");
- return 0;
- }
-
複製代碼 |