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

TOP

返回列表