返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {

  7.         re:
  8.         system("cls");       
  9.         srand(time(NULL));
  10.         int player,pc;
  11.         string n[]={"剪刀","石頭","布"};
  12.         cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
  13.         cin>>player;
  14.         pc=rand()%3+1;
  15.         cout<<"你出"<<n[player-1]<<endl;
  16.         cout<<"電腦出"<<n[pc-1]<<endl;
  17.          
  18.         if(player==pc)
  19.         {
  20.                 cout<<"平手"<<endl;
  21.         }
  22.         else if(player==1 && pc==2)
  23.         {
  24.                 cout<<"電腦贏了"<<endl;
  25.         }
  26.         else if(player==2 && pc==3)
  27.         {
  28.                 cout<<"電腦贏了"<<endl;
  29.         }
  30.         else if(player==3 && pc==1)
  31.         {
  32.                 cout<<"電腦贏了"<<endl;
  33.         }
  34.        
  35.         else if(player==2 && pc==1)
  36.         {
  37.                 cout<<"你贏了"<<endl;
  38.         }
  39.         else if(player==3 && pc==2)
  40.         {
  41.                 cout<<"你贏了"<<endl;
  42.         }
  43.         else if(player==1 && pc==3)
  44.         {
  45.                 cout<<"你贏了"<<endl;
  46.         }
  47.        
  48.        
  49.        
  50.        
  51.                
  52.         system("pause");
  53.         goto re;
  54.         return 0;       
  55. }       
  56.        
  57.        
複製代碼

TOP

返回列表