返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.    re:
  8.             srand(time(NULL));
  9.     int player, computer;
  10.      string meth[3]={"剪刀","石頭","布"};
  11.      
  12.     cout<<"請出拳!   (1)"+meth[0]+"(2)"+meth[1]+"(3)"+meth[2]+":  ";
  13.     cin>>player;
  14.     computer=rand()%3+1;
  15.     cout<<"你出"<<meth[player-1]<<"!"<<endl;
  16.     srand(time(NULL));
  17.      computer = rand()%3+1;
  18.     cout<<"電腦出"+meth[computer-1]+"!"<<endl;
  19.     if(computer==player)
  20.     cout<<"平手"<<endl;
  21.     else if((player==1 && computer==3)||(player==2&&computer==1)||(player==3&&computer==2))
  22.                         cout<<"你贏了!"<<endl;
  23.         else{       
  24.         cout<<"電腦贏了"<<endl;
  25.                 }
  26.    
  27.     goto re;
  28.     system("pause");   
  29.     return 0;
  30. }
複製代碼

TOP

返回列表