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

TOP

返回列表