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