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

TOP

返回列表