返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     int computer,player,win = 0,lost=0;
  8.     srand(time(NULL));
  9.     string name [4]= {"剪子","石子","布","over"};
  10.     cout<<"出拳(1)剪子(2)石子(3)布(4)over";
  11.     cin>>player;
  12.     if(player == 1||player == 2||player == 3)
  13.     {   
  14.         computer = rand()%3+1;        
  15.         cout<<"你出"<<name[player-1];
  16.         cout<<endl;
  17.         cout<<"電腦出"<<name[computer-1];
  18.         if(player == 1)
  19.         {
  20.             if(computer == 1)
  21.                 cout<<"Again!";
  22.             if(computer == 2)
  23.             {
  24.                 cout<<"You Lost!";
  25.                 lost+=1;
  26.             }
  27.             if(computer == 3)
  28.             {
  29.                 cout<<"You Win!";
  30.                 win+=1;
  31.             }         
  32.         }
  33.         if(player == 2)
  34.         {
  35.             if(computer == 2)
  36.                 cout<<"Again!";
  37.             if(computer == 3)
  38.             {
  39.                 cout<<"You Lost!";
  40.                 lost+=1;
  41.             }
  42.             if(computer == 1)
  43.             {
  44.                 cout<<"You Win!";
  45.                 win+=1;
  46.             }         
  47.         }
  48.         if(player == 3)
  49.         {
  50.             if(computer == 3)
  51.                 cout<<"Again!";
  52.             if(computer == 1)
  53.             {
  54.                 cout<<"You Lost!";
  55.                 lost+=1;
  56.             }
  57.             if(computer == 2)
  58.             {
  59.                 cout<<"You Win!";
  60.                 win+=1;
  61.             }         
  62.         }
  63.         if(player == 4)
  64.     {
  65.         cout<<"win:"<<win<<" lost:"<<lost<<endl;     
  66.     }
  67.         cout<<endl;
  68.     }
  69.    
  70.     else
  71.         cout<<"You are beach"<<endl;
  72.     goto re;
  73.     system("pause");
  74.     return 0;   
  75. }
複製代碼

TOP

返回列表