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