返回列表 發帖
本帖最後由 洪榮辰 於 2024-7-20 16:24 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     srand(time(NULL));
  9.     int p, c;
  10.     string n[]={"剪刀","石頭","布"};
  11.     cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
  12.     cin>>p;
  13.     c=rand()%3+1;
  14.     cout<<"你出"<<n[p-1]<<"!"<<endl;
  15.     cout<<"電腦出"<<n[c-1]<<"!"<<endl;
  16.     if(p==c)
  17.         {cout<<"平手!"<<endl;}
  18.     else if(p==1 && c==2)
  19.         {cout<<"你輸了!"<<endl;}
  20.     else if(p==1 && c==3)
  21.         {cout<<"你贏了!"<<endl;}
  22.     else if(p==2 && c==1)
  23.         {cout<<"你贏了!"<<endl;}
  24.     else if(p==2 && c==3)
  25.         {cout<<"你輸了!"<<endl;}
  26.     else if(p==3 && c==1)
  27.         {cout<<"你輸了!"<<endl;}
  28.     else if(p==3 && c==2)
  29.         {cout<<"你贏了!"<<endl;}
  30.     cout<<endl;
  31.     goto re;
  32.     system("pause");
  33.     return 0;
  34. }
複製代碼

TOP

返回列表