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

  11.     re:

  12.     cin>>player;
  13.     cout<<"你出"+meth[player-1]+"!"<<endl;
  14.     srand(time(NULL));
  15.     computer = rand()%3+1;   
  16.     cout<<"電腦"+meth[computer-1]+"!"<<endl;
  17.    
  18.     goto  re;
  19.     system("pause");
  20.     return 0;
  21. }
複製代碼

TOP

返回列表