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

TOP

返回列表