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