返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     srand(time(NULL));
  8.     string name[3]={"剪刀","石頭","布"};
  9.     int player, computer;
  10.     cout<<"請出拳! (1)剪刀 (2)石頭 (3)布  ";
  11.     cin>>player;
  12.     cout<<"你出"<<name[player-1]<<"!"<<"\n";
  13.    
  14.     computer=rand()%3+1;
  15.     cout<<"電腦出"<<name[computer-1]<<"!"<<"\n";
  16.     goto re;
  17.     system("pause");
  18.     return 0;   
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     srand(time(NULL));
  7.     int player, computer;
  8.     string name[3]={"剪刀","石頭","布"};
  9.     re:  
  10.     cout<<"請出拳! (1)剪刀 (2)石頭 (3)布"<<endl;
  11.     cin>>player;
  12.     cout<<"你出"<<name[player-1]<<"!"<<endl;
  13.     computer=rand()%3+1;
  14.     cout<<"電腦出"<<name[computer-1]<<"!"<<endl;
  15.     if((player==1 and computer==3)or(player==2 and computer==1)or(player==3 and computer==2))
  16.         cout<<"you win!!"<<endl;
  17.     else if((player==1 and computer==2)or(player==2 and computer==3)or(player==3 and computer==1))
  18.         cout<<"you lose!!"<<endl;
  19.     else
  20.         cout<<"fair!!"<<endl;
  21.     goto re;
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

TOP

返回列表