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

TOP

返回列表