返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {         
  7.      int player=0;
  8.      int com=0;
  9.      string mora[]={"剪刀","石頭","布"};
  10.      cout<<"請出拳(1剪刀.2石頭3布)"<<endl;
  11.      cin>>player;
  12.      cout<<"電腦出拳中。。。"<<endl;
  13.      srand(time(NULL));
  14.      com=rand()%3+1;
  15.      cout<<"電腦出"<<mora[com+1]<<endl ;
  16.       if((player==1&&com==3))
  17.      {
  18.        cout<<"你贏了"<<endl;   
  19.      }
  20.      else if((player==2&&com==1))
  21.      {
  22.       cout<<"你贏了"<<endl;   
  23.      }
  24.      else if((player==3&&com==1))
  25.      {
  26.       cout<<"你贏了"<<endl;   
  27.      }
  28.      else if(player=com)
  29.      {
  30.      cout<<"平手"<<endl;
  31.      }
  32.      else
  33.      {
  34.        cout<<"你輸了"<<endl;  
  35.      }
  36.      
  37.     system("pause");
  38.     return 0;
  39. }
複製代碼

TOP

返回列表