返回列表 發帖

[作業] 賽馬程式 (七)

本帖最後由 tonyh 於 2013-11-30 13:59 編輯

加入goto敘述, 使可以重複遊戲,
記得對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0;
  7.     int bet,buyin,option,winner;
  8.     re1:
  9.     int a=0,b=0,c=0,d=0,r;
  10.     system("cls");   
  11.     cout<<"$ 財源滾滾賽馬場 $"<<endl;
  12.     cout<<"---------------------------------------------------------------------|終點|"<<endl;
  13.     cout<<"◥1◣"<<endl;
  14.     cout<<"◥2◣"<<endl;
  15.     cout<<"◥3◣"<<endl;
  16.     cout<<"◥4◣"<<endl;
  17.     cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  18.     cout<<"(1)買入 (2)下注 (3)離開  請選擇: ";
  19.     cin>>option;
  20.     if(option==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>buyin;
  24.         balance+=buyin;   //i+=2  i=i+2
  25.         goto re1;
  26.     }else if(option==2)
  27.     {
  28.         cout<<"下注: ";
  29.         cin>>bet;
  30.         if(bet>balance)
  31.         {
  32.             cout<<"可用餘額不足!請先買入!"<<endl<<endl;
  33.             system("pause");
  34.             goto re1;  
  35.         }else
  36.         {
  37.             cout<<endl<<"(1)◥1◣ (2)◥2◣ (3)◥3◣ (4)◥4◣ 請選擇: ";
  38.             cin>>option;
  39.             cout<<"比賽即將開始!"<<endl<<endl;   
  40.         }
  41.     }else if(option==3)
  42.     {
  43.         goto end;  
  44.     }else
  45.     {
  46.         cout<<"輸入錯誤!"<<endl<<endl;
  47.         system("pause");
  48.         goto re1;     
  49.     }
  50.     system("pause");
  51.     system("cls");
  52.     srand(time(NULL));
  53.     while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
  54.     {
  55.         r=rand()%4;    //產生0~3之隨機亂數
  56.         if(r==0)
  57.             a++;
  58.         if(r==1)
  59.             b++;
  60.         if(r==2)
  61.             c++;
  62.         if(r==3)
  63.             d++;
  64.         cout<<"比賽進行中"<<endl;
  65.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  66.         for(int i=1;i<=a;i++)
  67.             cout<<" ";
  68.         cout<<"◥1◣"<<endl;
  69.         for(int i=1;i<=b;i++)
  70.             cout<<" ";
  71.         cout<<"◥2◣"<<endl;
  72.         for(int i=1;i<=c;i++)
  73.             cout<<" ";
  74.         cout<<"◥3◣"<<endl;
  75.         for(int i=1;i<=d;i++)
  76.             cout<<" ";
  77.         cout<<"◥4◣"<<endl;
  78.         system("cls");
  79.     }
  80.         if(a>b && a>c && a>d)
  81.             winner=1;
  82.         else if(b>a && b>c && b>d)
  83.             winner=2;
  84.         else if(c>a && c>b && c>d)
  85.             winner=3;
  86.         else
  87.             winner=4;
  88.         cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
  89.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  90.         for(int i=1;i<=a;i++)
  91.             cout<<" ";
  92.         cout<<"◥1◣"<<endl;
  93.         for(int i=1;i<=b;i++)
  94.             cout<<" ";
  95.         cout<<"◥2◣"<<endl;
  96.         for(int i=1;i<=c;i++)
  97.             cout<<" ";
  98.         cout<<"◥3◣"<<endl;
  99.         for(int i=1;i<=d;i++)
  100.             cout<<" ";
  101.         cout<<"◥4◣"<<endl;
  102.         if(winner==option)
  103.         {
  104.             cout<<"贏了"<<bet*3<<"元!"<<endl;
  105.             balance+=bet*3;  //balance=balance+bet*3
  106.         }   
  107.         else
  108.         {
  109.             cout<<"輸了"<<bet<<"元!"<<endl;
  110.             balance-=bet;
  111.         }
  112.         system("pause");
  113.         goto re1;
  114.     end:
  115.     system("pause");   
  116.     return 0;
  117. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0, n=1, money=0;
  7.     int option, buyin, bet, winner;
  8.     re1:
  9.     int a=0, b=0, c=0, d=0, r;
  10.     system("cls");
  11.     cout<<"「好事雙成」賽馬場 第"<<n<<"局"<<endl;
  12.     cout<<"---------------------------------------------------------|終點"<<endl;
  13.     cout<<"◥1◣"<<endl;
  14.     cout<<"◥2◣"<<endl;
  15.     cout<<"◥3◣"<<endl;
  16.     cout<<"◥4◣"<<endl;
  17.     re2:
  18.     cout<<endl<<"可用餘額:"<<balance<<"元"<<endl<<endl;
  19.     cout<<"(1)買入(2)下注(3)離開 請選擇: ";
  20.     cin>>option;
  21.     if(option==1)
  22.     {
  23.         cout<<"買入: ";
  24.         cin>>buyin;
  25.         balance+=buyin;
  26.         goto re1;
  27.     }else if(option==2)
  28.     {
  29.         if(balance==0)
  30.         {
  31.              cout<<"可用餘額不足!請先買入!" <<endl<<endl;
  32.              system("pause");
  33.              goto re1;
  34.         }
  35.         cout<<"下注: ";
  36.         cin>>bet;
  37.         if(bet>balance)
  38.         {
  39.              cout<<"可用餘額不足!請先買入!" <<endl<<endl;
  40.              system("pause");
  41.              goto re1;         
  42.         }else
  43.         {
  44.              cout<<endl<<"(1)◥1◣(2)◥2◣(3)◥3◣(4)◥4◣請選擇: ";
  45.              cin>>option;
  46.              cout<<"比賽即將開始!"<<endl<<endl;
  47.              system("pause");
  48.         }
  49.     }else if(option==3)
  50.     {
  51.         goto end;  
  52.     }else
  53.     {
  54.         cout<<"輸入錯誤!"<<endl<<endl;
  55.         system("pause");
  56.         goto re1;
  57.     }
  58.     srand(time(NULL));
  59.     while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
  60.     {
  61.              r=rand()%4;
  62.              if(r==0)
  63.                a++;     
  64.              else if(r==1)
  65.                b++;   
  66.              else if(r==2)
  67.                c++;   
  68.              else
  69.                d++;   
  70.              cout<<"比賽進行中...";
  71.              cout<<endl<<"---------------------------------------------------------|終點"<<endl;
  72.                for(int i=1;i<=a;i++)
  73.                  cout<<" ";
  74.                cout<<"◥1◣"<<endl;     
  75.                for(int i=1;i<=b;i++)
  76.                  cout<<" ";
  77.                cout<<"◥2◣"<<endl;
  78.                for(int i=1;i<=c;i++)
  79.                  cout<<" ";
  80.                cout<<"◥3◣"<<endl;     
  81.                for(int i=1;i<=d;i++)
  82.                  cout<<" ";
  83.                cout<<"◥4◣"<<endl;
  84.                system("cls");                           
  85.          }
  86.                if(a>b&&a>c&&a>d)
  87.                {
  88.                     cout<<"◥1◣勝出!";
  89.                     winner=1;            
  90.                }else if(b>a&&b>c&&b>d)
  91.                {
  92.                     cout<<"◥2◣勝出!";
  93.                     winner=2;            
  94.                }else if(c>a&&c>b&&c>d)
  95.                {
  96.                     cout<<"◥3◣勝出!";
  97.                     winner=3;            
  98.                }else
  99.                {
  100.                     cout<<"◥4◣勝出!";
  101.                     winner=4;            
  102.                }   
  103.                cout<<"比賽結束!"<<endl;
  104.                cout<<"---------------------------------------------------------|終點"<<endl;
  105.                for(int i=1;i<=a;i++)
  106.                  cout<<" ";
  107.                cout<<"◥1◣"<<endl;     
  108.                for(int i=1;i<=b;i++)
  109.                  cout<<" ";
  110.                cout<<"◥2◣"<<endl;
  111.                for(int i=1;i<=c;i++)
  112.                  cout<<" ";
  113.                cout<<"◥3◣"<<endl;     
  114.                for(int i=1;i<=d;i++)
  115.                  cout<<" ";
  116.                cout<<"◥4◣"<<endl;
  117.      if(option==3)         
  118.      {
  119.           cout<<endl<<"贏了"<<bet*3<<"元!"<<endl;
  120.           balance+=bet*3;
  121.           money+=bet*3;                                    
  122.      }else
  123.      {
  124.           cout<<endl<<"損失"<<bet<<"元!"<<endl;
  125.           balance-=bet;
  126.           money-=bet;                           
  127.      }
  128.      goto re1;
  129.      end:                    
  130.     system("pause");
  131.     return 0;  
  132. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int money=0,cg,n=1,buy,bet,player,choose;
  8.     choose:
  9.     cout<<"第"<<n<<"場"<<endl;      
  10.     cout<<"$ 財源滾滾賽馬場 $"<<endl;
  11.     cout<<endl<<"-----------------------------------------------------------------------|終點|"<<endl;
  12.     cout<<"◢1◤"<<endl;
  13.     cout<<"◢2◤"<<endl;
  14.     cout<<"◢3◤"<<endl;
  15.     cout<<"◢4◤"<<endl;
  16.     cout<<"您有"<<money<<"元"<<endl;
  17.     cout<<"需先買入並下注"<<endl;
  18.     cout<<"(1)買入(2)賭(3)離開"<<endl;
  19.     cin>>choose;
  20.     if(choose==1)
  21.     {
  22.         cout<<"要買多少?"<<endl;
  23.         cin>>buy;
  24.         money=money+buy;
  25.         system("cls");
  26.         goto choose;            
  27.     }else if(choose==2)
  28.     {
  29.         cout<<"要賭哪位選手?(共有4位)"<<endl;
  30.         cin>>player;
  31.         if(player>4 || player<1)
  32.         {
  33.             system("cls");
  34.             goto choose;         
  35.         }
  36.         cout<<"要賭多少?"<<endl;
  37.         cin>>bet;
  38.         if(bet>money)
  39.         {
  40.             system("cls");
  41.             goto choose;         
  42.         }
  43.         cout<<"(1)比賽開始(2)重選"<<endl;
  44.         cin>>cg;
  45.         system("cls");
  46.         if(cg==1)
  47.         goto re;
  48.         else if(cg==2)
  49.         goto choose;
  50.         else
  51.         cout<<"輸入錯誤"<<endl;
  52.         goto choose;      
  53.     }else if(choose==3)
  54.     {
  55.         system("cls");
  56.     }   
  57.     else
  58.     cout<<"輸入錯誤"<<endl;
  59.     system("cls");
  60.     goto choose;
  61.     re:
  62.     cout<<"$ 財源滾滾賽馬場 $"<<endl<<endl;
  63.     cout<<endl<<"-----------------------------------------------------------------------|終點|"<<endl;
  64.     cout<<"◢1◤"<<endl;
  65.     cout<<"◢2◤"<<endl;
  66.     cout<<"◢3◤"<<endl;
  67.     cout<<"◢4◤"<<endl;
  68.     system("pause");
  69.     system("cls");
  70.     srand(time(NULL));
  71.     int a=0 ,b=0, c=0, d=0,r,bigger,biggest,more;
  72.     while((a!=65) && (b!=65) && (c!=65) && (d!=65))
  73.     {
  74.         r=rand()%4;
  75.         if(r==0)              
  76.         a++;
  77.         else if(r==1)              
  78.         b++;
  79.         else if(r==2)              
  80.         c++;
  81.         else if(r==3)              
  82.         d++;
  83.     cout<<"比賽進行中"<<endl<<endl;
  84.     cout<<endl<<"-----------------------------------------------------------------|終點|"<<endl;
  85.     for(int i=1;i<=a;i++)
  86.         cout<<" ";
  87.     cout<<"◢1◤"<<endl;
  88.     for(int i=1;i<=b;i++)
  89.         cout<<" ";
  90.     cout<<"◢2◤"<<endl;
  91.     for(int i=1;i<=c;i++)
  92.         cout<<" ";
  93.     cout<<"◢3◤"<<endl;
  94.     for(int i=1;i<=d;i++)
  95.         cout<<" ";
  96.     cout<<"◢4◤"<<endl;
  97.     system("cls");         
  98.     }
  99.     more=(a>b)?a:b;
  100.     bigger=(c>d)?c:d;
  101.     biggest=(bigger>more)?bigger:more;
  102.     if(biggest==a)
  103.         cout<<"1號勝利"<<endl;
  104.     else if(biggest==b)
  105.              cout<<"2號勝利"<<endl;
  106.     else if(biggest==c)
  107.              cout<<"3號勝利"<<endl;
  108.     else if(biggest==d)
  109.     cout<<"4號勝利"<<endl;
  110.     cout<<"第"<<n<<"場"<<endl;
  111.     cout<<endl<<"-----------------------------------------------------------------|終點|"<<endl;
  112.     for(int i=1;i<=a;i++)
  113.         cout<<" ";
  114.     cout<<"◢1◤"<<endl;
  115.     for(int i=1;i<=b;i++)
  116.         cout<<" ";
  117.     cout<<"◢2◤"<<endl;
  118.     for(int i=1;i<=c;i++)
  119.         cout<<" ";
  120.     cout<<"◢3◤"<<endl;
  121.     for(int i=1;i<=d;i++)
  122.         cout<<" ";
  123.     cout<<"◢4◤"<<endl;
  124.     n++;
  125.     if(biggest==a && player==1)
  126.     {
  127.         money=money+bet;
  128.         cout<<"恭喜你贏了"<<bet<<"元"<<endl;              
  129.     }else if(biggest==b && player==2)
  130.     {
  131.         money=money+bet;
  132.         cout<<"恭喜你贏了"<<bet<<"元"<<endl;              
  133.     }else if(biggest==c && player==3)
  134.     {
  135.         money==money+bet;
  136.         cout<<"恭喜你贏了"<<bet<<"元"<<endl;              
  137.     }else if(biggest==d && player==4)
  138.     {
  139.         money=money+bet;
  140.         cout<<"恭喜你贏了"<<bet<<"元"<<endl;              
  141.     }else
  142.     {
  143.         money=money-bet;
  144.         cout<<"恭喜你輸了"<<bet<<"元"<<endl;     
  145.     }
  146.     system("pause");
  147.     system("cls");
  148.     goto choose;
  149.     system("pause");   
  150.     return 0;
  151. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0;
  7.     int bet,buyin,option,winner;
  8.     re1:
  9.     int a=0,b=0,c=0,d=0,r;
  10.     system("cls");   
  11.     cout<<"$ 財源滾滾賽馬場 $"<<endl;
  12.     cout<<"---------------------------------------------------------------------|終點|"<<endl;
  13.     cout<<"◥1◣"<<endl;
  14.     cout<<"◥2◣"<<endl;
  15.     cout<<"◥3◣"<<endl;
  16.     cout<<"◥4◣"<<endl;
  17.     cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  18.     cout<<"(1)買入 (2)下注 (3)離開  請選擇: ";
  19.     cin>>option;
  20.     if(option==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>buyin;
  24.         balance+=buyin;   //i+=2  i=i+2
  25.         goto re1;
  26.     }else if(option==2)
  27.     {
  28.         cout<<"下注: ";
  29.         cin>>bet;
  30.         if(bet>balance)
  31.         {
  32.             cout<<"可用餘額不足!請先買入!"<<endl<<endl;
  33.             system("pause");
  34.             goto re1;  
  35.         }else
  36.         {
  37.             cout<<endl<<"(1)◥1◣ (2)◥2◣ (3)◥3◣ (4)◥4◣ 請選擇: ";
  38.             cin>>option;
  39.             cout<<"比賽即將開始!"<<endl<<endl;   
  40.         }
  41.     }else if(option==3)
  42.     {
  43.         goto end;  
  44.     }else
  45.     {
  46.         cout<<"輸入錯誤!"<<endl<<endl;
  47.         system("pause");
  48.         goto re1;     
  49.     }
  50.     system("pause");
  51.     system("cls");
  52.     srand(time(NULL));
  53.     while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
  54.     {
  55.         r=rand()%4;    //產生0~3之隨機亂數
  56.         if(r==0)
  57.             a++;
  58.         if(r==1)
  59.             b++;
  60.         if(r==2)
  61.             c++;
  62.         if(r==3)
  63.             d++;
  64.         cout<<"比賽進行中"<<endl;
  65.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  66.         for(int i=1;i<=a;i++)
  67.             cout<<" ";
  68.         cout<<"◥1◣"<<endl;
  69.         for(int i=1;i<=b;i++)
  70.             cout<<" ";
  71.         cout<<"◥2◣"<<endl;
  72.         for(int i=1;i<=c;i++)
  73.             cout<<" ";
  74.         cout<<"◥3◣"<<endl;
  75.         for(int i=1;i<=d;i++)
  76.             cout<<" ";
  77.         cout<<"◥4◣"<<endl;
  78.         system("cls");
  79.     }
  80.         if(a>b && a>c && a>d)
  81.             winner=1;
  82.         else if(b>a && b>c && b>d)
  83.              winner=2;
  84.         else if(c>a && c>b && c>d)
  85.              winner=3;
  86.         else
  87.             winner=4;
  88.         cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
  89.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  90.         for(int i=1;i<=a;i++)
  91.             cout<<" ";
  92.         cout<<"◥1◣"<<endl;
  93.         for(int i=1;i<=b;i++)
  94.             cout<<" ";
  95.         cout<<"◥2◣"<<endl;
  96.         for(int i=1;i<=c;i++)
  97.             cout<<" ";
  98.         cout<<"◥3◣"<<endl;
  99.         for(int i=1;i<=d;i++)
  100.             cout<<" ";
  101.         cout<<"◥4◣"<<endl<<endl;
  102.         if(option==winner)
  103.         {
  104.                           cout<<"恭喜贏得"<<bet*3<<"元"<<endl;
  105.                           balance+=bet*3;
  106.                           }
  107.         else
  108.         {
  109.                           cout<<"可悲~輸了"<<bet<<"元"<<endl;
  110.                           balance-=bet;                     
  111.                           }
  112.         system("pause");
  113.         goto re1;      
  114.     end:

  115.     system("pause");   
  116.     return 0;
  117. }
複製代碼

TOP

本帖最後由 許逸群 於 2013-11-23 11:57 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0, n=1, money=0;
  7.     int option, buyin, bet, winner;
  8.     re1:
  9.     int a=0, b=0, c=0, d=0, r;
  10.     system("cls");
  11.     cout<<"賽馬場 第"<<n<<"局"<<endl;
  12.     cout<<"---------------------------------------------------------|終點"<<endl;
  13.     cout<<"◥1◣"<<endl;
  14.     cout<<"◥2◣"<<endl;
  15.     cout<<"◥3◣"<<endl;
  16.     cout<<"◥4◣"<<endl;
  17.     re2:
  18.     cout<<endl<<"可用餘額:"<<balance<<"元"<<endl<<endl;
  19.     cout<<"(1)買入(2)下注(3)離開 請選擇: ";
  20.     cin>>option;
  21.     if(option==1)
  22.     {
  23.         cout<<"買入: ";
  24.         cin>>buyin;
  25.         balance+=buyin;
  26.         goto re1;
  27.     }else if(option==2)
  28.     {
  29.         if(balance==0)
  30.         {
  31.              cout<<"可用餘額不足!請先買入!" <<endl<<endl;
  32.              system("pause");
  33.              goto re1;
  34.         }
  35.         cout<<"下注: ";
  36.         cin>>bet;
  37.         if(bet>balance)
  38.         {
  39.              cout<<"可用餘額不足!請先買入!" <<endl<<endl;
  40.              system("pause");
  41.              goto re1;         
  42.         }else
  43.         {
  44.              cout<<endl<<"(1)◥1◣(2)◥2◣(3)◥3◣(4)◥4◣請選擇: ";
  45.              cin>>option;
  46.              cout<<"比賽即將開始!"<<endl<<endl;
  47.              system("pause");
  48.         }
  49.     }else if(option==3)
  50.     {
  51.         goto end;  
  52.     }else
  53.     {
  54.         cout<<"輸入錯誤!"<<endl<<endl;
  55.         system("pause");
  56.         goto re1;
  57.     }
  58.     srand(time(NULL));
  59.     while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
  60.     {
  61.              r=rand()%4;
  62.              if(r==0)
  63.                a++;     
  64.              else if(r==1)
  65.                b++;   
  66.              else if(r==2)
  67.                c++;   
  68.              else
  69.                d++;   
  70.              cout<<"比賽進行中...";
  71.              cout<<endl<<"---------------------------------------------------------|終點"<<endl;
  72.                for(int i=1;i<=a;i++)
  73.                  cout<<" ";
  74.                cout<<"◥1◣"<<endl;     
  75.                for(int i=1;i<=b;i++)
  76.                  cout<<" ";
  77.                cout<<"◥2◣"<<endl;
  78.                for(int i=1;i<=c;i++)
  79.                  cout<<" ";
  80.                cout<<"◥3◣"<<endl;     
  81.                for(int i=1;i<=d;i++)
  82.                  cout<<" ";
  83.                cout<<"◥4◣"<<endl;
  84.                system("cls");                           
  85.          }
  86.                if(a>b&&a>c&&a>d)
  87.                {
  88.                     cout<<"◥1◣勝出!";
  89.                     winner=1;            
  90.                }else if(b>a&&b>c&&b>d)
  91.                {
  92.                     cout<<"◥2◣勝出!";
  93.                     winner=2;            
  94.                }else if(c>a&&c>b&&c>d)
  95.                {
  96.                     cout<<"◥3◣勝出!";
  97.                     winner=3;            
  98.                }else
  99.                {
  100.                     cout<<"◥4◣勝出!";
  101.                     winner=4;            
  102.                }   
  103.                cout<<"比賽結束!"<<endl;
  104.                cout<<"---------------------------------------------------------|終點"<<endl;
  105.                for(int i=1;i<=a;i++)
  106.                  cout<<" ";
  107.                cout<<"◥1◣"<<endl;     
  108.                for(int i=1;i<=b;i++)
  109.                  cout<<" ";
  110.                cout<<"◥2◣"<<endl;
  111.                for(int i=1;i<=c;i++)
  112.                  cout<<" ";
  113.                cout<<"◥3◣"<<endl;     
  114.                for(int i=1;i<=d;i++)
  115.                  cout<<" ";
  116.                cout<<"◥4◣"<<endl;
  117.      if(option==3)         
  118.      {
  119.           cout<<endl<<"贏了"<<bet*3<<"元!"<<endl;
  120.           balance+=bet*3;
  121.           money+=bet*3;                                    
  122.      }else
  123.      {
  124.           cout<<endl<<"損失"<<bet<<"元!"<<endl;
  125.           balance-=bet;
  126.           money-=bet;                           
  127.      }
  128.      goto re1;
  129.      end:                    
  130.     system("pause");
  131.     return 0;  
  132. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0;
  7.     int bet,buyin,option,winner;
  8.     re1:
  9.     int a=0,b=0,c=0,d=0,r;
  10.     system("cls");   
  11.     cout<<"$ 財源滾滾賽馬場 $"<<endl;
  12.     cout<<"---------------------------------------------------------------------|終點|"<<endl;
  13.     cout<<"◥1◣"<<endl;
  14.     cout<<"◥2◣"<<endl;
  15.     cout<<"◥3◣"<<endl;
  16.     cout<<"◥4◣"<<endl;
  17.     cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  18.     cout<<"(1)買入 (2)下注 (3)離開  請選擇: ";
  19.     cin>>option;
  20.     if(option==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>buyin;
  24.         balance+=buyin;
  25.         goto re1;
  26.     }else if(option==2)
  27.     {
  28.         cout<<"下注: ";
  29.         cin>>bet;
  30.         if(bet>balance)     
  31.         {
  32.            cout<<"可用餘額不足!請先買入再來!"<<endl<<endl;
  33.             system("pause");
  34.             goto re1;                                   
  35.         }else   
  36.         {
  37.           cout<<endl<<"(1)◥1◣(2)◥2◣(3)◥3◣(4)◥4◣請選擇: ";
  38.             cin>>option;
  39.             cout<<"比賽即將開始!"<<endl<<endl;      
  40.         }
  41.     }else if(option==3)
  42.     {
  43.          goto end;            
  44.     }else
  45.     {
  46.          cout<<"輸入錯誤"<<endl<<endl;     
  47.          system("pause");
  48.          goto re1;
  49.     }
  50.     system("pause");
  51.     system("cls");
  52.     srand(time(NULL));
  53.     while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
  54.     {
  55.         r=rand()%4;
  56.         if(r==0)
  57.             a++;
  58.         if(r==1)
  59.             b++;
  60.         if(r==2)
  61.             c++;
  62.         if(r==3)
  63.             d++;
  64.         cout<<"比賽進行中"<<endl;
  65.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  66.         for(int i=1;i<=a;i++)
  67.             cout<<" ";
  68.         cout<<"◥1◣"<<endl;
  69.         for(int i=1;i<=b;i++)
  70.             cout<<" ";
  71.         cout<<"◥2◣"<<endl;
  72.         for(int i=1;i<=c;i++)
  73.             cout<<" ";
  74.         cout<<"◥3◣"<<endl;
  75.         for(int i=1;i<=d;i++)
  76.             cout<<" ";
  77.         cout<<"◥4◣"<<endl;
  78.         system("cls");
  79.     }
  80.         if(a>b && a>c && a>d)
  81.             winner=1;
  82.         else if(b>a && b>c && b>d)
  83.              winner=2;
  84.         else if(c>a && c>b && c>d)
  85.              winner=3;
  86.         else
  87.             winner=4;
  88.         cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
  89.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  90.         for(int i=1;i<=a;i++)
  91.             cout<<" ";
  92.         cout<<"◥1◣"<<endl;
  93.         for(int i=1;i<=b;i++)
  94.             cout<<" ";
  95.         cout<<"◥2◣"<<endl;
  96.         for(int i=1;i<=c;i++)
  97.             cout<<" ";
  98.         cout<<"◥3◣"<<endl;
  99.         for(int i=1;i<=d;i++)
  100.             cout<<" ";
  101.         cout<<"◥4◣"<<endl;
  102.          if(winner==option)
  103.          {        
  104.                cout<<"贏了"<<bet*3<<"元"<<endl;
  105.                balance+=bet*3;
  106.          }      
  107.          else
  108.          {
  109.                cout<<"輸了"<<bet<<"元"<<endl;
  110.                balance-=bet;
  111.          }
  112.     system("pause");     
  113.     goto re1;                    
  114.     end:      
  115.     system("pause");   
  116.     return 0;
  117. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0;
  7.     int bet,buyin,option,winner;
  8.     re1:
  9.     int a=0,b=0,c=0,d=0,r;
  10.     system("cls");   
  11.     cout<<"$ 財源滾滾賽馬場 $"<<endl;
  12.     cout<<"---------------------------------------------------------------------|終點|"<<endl;
  13.     cout<<"◥1◣"<<endl;
  14.     cout<<"◥2◣"<<endl;
  15.     cout<<"◥3◣"<<endl;
  16.     cout<<"◥4◣"<<endl;
  17.     cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  18.     cout<<"(1)買入 (2)下注 (3)離開  請選擇: ";
  19.     cin>>option;
  20.     if(option==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>buyin;
  24.         balance+=buyin;   //i+=2  i=i+2
  25.         goto re1;
  26.     }else if(option==2)
  27.     {
  28.         cout<<"下注: ";
  29.         cin>>bet;
  30.         if(bet>balance)
  31.         {
  32.             cout<<"可用餘額不足!請先買入!"<<endl<<endl;
  33.             system("pause");
  34.             goto re1;  
  35.         }else
  36.         {
  37.             cout<<endl<<"(1)◥1◣ (2)◥2◣ (3)◥3◣ (4)◥4◣ 請選擇: ";
  38.             cin>>option;
  39.             cout<<"比賽即將開始!"<<endl<<endl;   
  40.         }
  41.     }else if(option==3)
  42.     {
  43.         goto end;  
  44.     }else
  45.     {
  46.         cout<<"輸入錯誤!"<<endl<<endl;
  47.         system("pause");
  48.         goto re1;     
  49.     }
  50.     system("pause");
  51.     system("cls");
  52.     srand(time(NULL));
  53.     while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
  54.     {
  55.         r=rand()%4;    //產生0~3之隨機亂數
  56.         if(r==0)
  57.             a++;
  58.         if(r==1)
  59.             b++;
  60.         if(r==2)
  61.             c++;
  62.         if(r==3)
  63.             d++;
  64.         cout<<"比賽進行中"<<endl;
  65.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  66.         for(int i=1;i<=a;i++)
  67.             cout<<" ";
  68.         cout<<"◥1◣"<<endl;
  69.         for(int i=1;i<=b;i++)
  70.             cout<<" ";
  71.         cout<<"◥2◣"<<endl;
  72.         for(int i=1;i<=c;i++)
  73.             cout<<" ";
  74.         cout<<"◥3◣"<<endl;
  75.         for(int i=1;i<=d;i++)
  76.             cout<<" ";
  77.         cout<<"◥4◣"<<endl;
  78.         system("cls");
  79.     }
  80.         if(a>b && a>c && a>d)
  81.             winner=1;
  82.         else if(b>a && b>c && b>d)
  83.             winner=2;
  84.         else if(c>a && c>b && c>d)
  85.             winner=3;
  86.         else
  87.             winner=4;
  88.         cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
  89.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  90.         for(int i=1;i<=a;i++)
  91.             cout<<" ";
  92.         cout<<"◥1◣"<<endl;
  93.         for(int i=1;i<=b;i++)
  94.             cout<<" ";
  95.         cout<<"◥2◣"<<endl;
  96.         for(int i=1;i<=c;i++)
  97.             cout<<" ";
  98.         cout<<"◥3◣"<<endl;
  99.         for(int i=1;i<=d;i++)
  100.             cout<<" ";
  101.         cout<<"◥4◣"<<endl;
  102.         if(winner==option)
  103.         {
  104.             cout<<"贏了"<<bet*3<<"元!"<<endl;
  105.             balance+=bet*3;  //balance=balance+bet*3
  106.         }   
  107.         else
  108.         {
  109.             cout<<"輸了"<<bet<<"元!"<<endl;
  110.             balance-=bet;
  111.         }
  112.         system("pause");
  113.         goto re1;
  114.     end:
  115.     system("pause");   
  116.     return 0;
  117. }
複製代碼

TOP

返回列表