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