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

  6.     while (true){  
  7.     int com;
  8.     int user;
  9.     int tryagain;
  10.    
  11.     srand(time(NULL));  
  12.     com =1+rand()%((3-1)+1);  
  13.     cout<<"請輸入要出的拳  1 = 剪刀   2 =石頭   3 = 布"<<endl;
  14.     cin>>user;
  15.     cout<<"你是:"<<user<<endl;

  16.      
  17.    
  18.     if(com == user)
  19.     {

  20.             switch(com)

  21.             {
  22.                   case 1:  
  23.                          cout<<"你出:剪刀,電腦出:剪刀"<<endl ;
  24.                          cout<<"平手"<<endl;
  25.                          break;

  26.                   case 2:
  27.                          cout<<"你出:石頭,電腦出:石頭"<<endl ;
  28.                          cout<<"平手"<<endl;
  29.                          break;

  30.                   case 3:  
  31.                          cout<<"你出:布,電腦出:布"<<endl ;
  32.                          cout<<"平手"<<endl;
  33.                          break;
  34.             }
  35.     }

  36.     if(com == 1)
  37.     {

  38.              if(user == 2)

  39.              {
  40.                      cout<<"你出:石頭,電腦出:剪刀"<<endl;
  41.                      cout<<"你贏了!!"<<endl;
  42.              }

  43.              else if(user == 3)  

  44.              {
  45.                   cout<<"你出:布,電腦出:剪刀"<<endl;
  46.                      cout<<"你輸了!!"<<endl;   
  47.              }

  48.     }
  49.     if(com == 2)

  50.     {
  51.              if(user == 3)
  52.              {

  53.                      cout<<"你出:布,電腦出:石頭"<<endl;
  54.                      cout<<"你贏了!!"<<endl;
  55.              }

  56.              else if(user == 1)
  57.              {

  58.                   cout<<"你出:剪刀,電腦出:石頭"<<endl;
  59.                      cout<<"你輸了!!"<<endl;     
  60.              }         

  61.     }

  62.     if(com == 3)

  63.     {  
  64.              if(user == 1)
  65.              {
  66.                      cout<<"你出:剪刀,電腦出:布"<<endl;
  67.                      cout<<"你贏了!!"<<endl;
  68.              }

  69.              else if(user == 2)
  70.              {

  71.                      cout<<"你出:石頭,電腦出:布"<<endl;
  72.                      cout<<"你輸了!!"<<endl;      
  73.              }         

  74.     }

  75.                         
  76.                     
  77.                     }     

  78.     system("pause");

  79.     return 0;

  80. }
複製代碼
明輝

TOP

返回列表