返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     re:
  8.     int x,y;
  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]+"";
  17.     srand(time(NULL));   
  18.     y=rand()%3+1;
  19.     cout<<"電腦出"+meth[y-1]<<endl;
  20.     if(y==x)
  21.     cout<<"平手"<<endl;
  22.     else if((x==1 && y==3)||(x==2&&y==1)||(x==3&&y==2))
  23.         cout<<"你贏了!"<<endl;
  24.     else{      
  25.         cout<<"電腦贏了"<<endl;
  26.     }
  27.     goto re;
  28.     system("pause");   
  29.     return 0;
  30. }
複製代碼

TOP

返回列表