返回列表 發帖

賽馬程式 (六)

1. 比對比賽結果與玩家下注, 判斷玩家贏了錢還是輸了錢.
2. 對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.

規則如下:
若最後勝出的選手與玩家下注相同, 玩家贏得下注金3倍的錢.
反之, 玩家損失下注金.




  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=1,balance=0,winner;
  7.     re1:
  8.     int a=0, b=0, c=0, d=0, r, option, buyin, bet;
  9.     system("cls");
  10.     cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
  11.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  12.     cout<<"◆"<<endl;
  13.     cout<<"★"<<endl;
  14.     cout<<"▲"<<endl;
  15.     cout<<"●"<<endl;
  16.     cout<<endl;
  17.     cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  18.     cout<<"(1)買入  (2)下注  (3)離開  請選擇: ";
  19.     cin>>option;
  20.     if(option==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>buyin;
  24.         balance+=buyin;   //balance=balance+buyin
  25.         goto re1;
  26.     }else if(option==2)
  27.     {
  28.         if(balance==0)
  29.         {
  30.             cout<<"可用餘額不足! 請先買入!"<<endl<<endl;
  31.             system("pause");
  32.             goto re1;
  33.         }
  34.         cout<<"下注: ";
  35.         cin>>bet;
  36.         if(bet>balance)
  37.         {
  38.             cout<<"可用餘額不足! 請先買入!"<<endl<<endl;
  39.             system("pause");
  40.             goto re1;   
  41.         }else
  42.         {
  43.             cout<<endl<<"(1)◆ (2)★ (3)▲ (4)●  請選擇: ";
  44.             cin>>option;
  45.             cout<<"比賽即將開始..."<<endl<<endl;
  46.             system("pause");   
  47.         }  
  48.     }else if(option==3)
  49.     {
  50.         goto end;  
  51.     }else
  52.     {
  53.         cout<<"輸入錯誤!"<<endl;
  54.         system("pause");
  55.         goto re1;
  56.     }
  57.     system("cls");
  58.     srand(time(NULL));
  59.     while(a!=75 && b!=75 && c!=75 && d!=75)
  60.     {
  61.         r=rand()%4;   //產生0~3之隨機亂數
  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<<"比賽進行中"<<endl;
  71.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  72.         for(int i=1; i<=a; i++)
  73.             cout<<" ";
  74.         cout<<"◆"<<endl;
  75.         for(int i=1; i<=b; i++)
  76.             cout<<" ";
  77.         cout<<"★"<<endl;
  78.         for(int i=1; i<=c; i++)
  79.             cout<<" ";
  80.         cout<<"▲"<<endl;
  81.         for(int i=1; i<=d; i++)
  82.             cout<<" ";
  83.         cout<<"●"<<endl;   
  84.         system("cls");      
  85.     }
  86.     cout<<"比賽結束! 由 ";
  87.     if(a==75)
  88.     {
  89.         cout<<"◆";
  90.         winner=1;
  91.     }
  92.     else if(b==75)
  93.     {
  94.         cout<<"★";
  95.         winner=2;
  96.     }
  97.     else if(c==75)
  98.     {
  99.         cout<<"▲";
  100.         winner=3;
  101.     }
  102.     else
  103.     {
  104.         cout<<"●";
  105.         winner=4;
  106.     }
  107.     cout<<" 先馳得點!"<<endl;
  108.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  109.     for(int i=1; i<=a; i++)
  110.         cout<<" ";
  111.     cout<<"◆"<<endl;
  112.     for(int i=1; i<=b; i++)
  113.         cout<<" ";
  114.     cout<<"★"<<endl;
  115.     for(int i=1; i<=c; i++)
  116.         cout<<" ";
  117.     cout<<"▲"<<endl;
  118.     for(int i=1; i<=d; i++)
  119.         cout<<" ";
  120.     cout<<"●"<<endl<<endl;
  121.     if(option==winner)
  122.     {
  123.         cout<<"贏了"<<bet*3<<"元!"<<endl;
  124.         balance+=bet*3;                  
  125.     }else
  126.     {
  127.         cout<<"損失"<<bet<<"元!"<<endl;
  128.         balance-=bet;
  129.     }
  130.     system("pause");
  131.     n++;
  132.     goto re1;
  133.     end:
  134.     system("pause");
  135.     return 0;   
  136. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

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

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x=1 ,mony=0 ,many;
  7.     re:
  8.     int a=0 ,b=0 ,c=0 ,d=0 ,z ,win ,buy ,bird ,n;
  9.     srand(time(NULL));
  10.     cout<<"第"<<x<<"場[萬事如意]賽馬場"<<endl;
  11.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  12.     cout<<"◆"<<endl;
  13.     cout<<"★"<<endl;
  14.     cout<<"㊣"<<endl;
  15.     cout<<"▼"<<endl<<endl;
  16.     cout<<"可用餘額:"<<mony<<"元"<<endl;
  17.     cout<<"(1)買入(2)下注(3)離開 請選擇:";
  18.     cin>>z;
  19.     if(z==1)
  20.     {
  21.         cout<<"買入:";
  22.         cin>>buy;
  23.         mony=mony+buy;
  24.         system("cls");
  25.         goto re;
  26.     }else if(z==2)
  27.     {
  28.         if(mony==0)
  29.         {
  30.             cout<<"餘額不足!請先買入!";
  31.             system("pause");
  32.             system("cls");
  33.             goto re;
  34.         }
  35.         cout<<"下注:";
  36.         cin>>bird;
  37.         if(bird>mony)
  38.         {
  39.             cout<<"餘額不足!請先買入!";
  40.             system("pause");
  41.             system("cls");
  42.             goto re;
  43.         }else if(bird<=mony)
  44.         {
  45.             cout<<"(1)■(2)★(3)㊣(4)▼ 請選擇:";
  46.             cin>>many;
  47.             cout<<"比賽即將開始>>>"<<endl<<endl;
  48.             system("pause");
  49.         }
  50.     }else if(z==3)
  51.     {
  52.         goto go;
  53.     }else
  54.     {
  55.         cout<<"輸入錯誤";
  56.         system("pause");
  57.         system("cls");
  58.         goto re;
  59.     }
  60.     system("pause");
  61.     while(a!=70 && b!=70 && c!=70 && d!=70)
  62.     {
  63.                 cout<<"比賽中"<<endl;
  64.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  65.         z=rand()%4+1;
  66.         if(z==1)
  67.         {
  68.             a+=2;
  69.         }
  70.         if(z==2)
  71.         {
  72.             b+=2;
  73.         }
  74.         if(z==3)
  75.         {
  76.             c+=2;
  77.         }
  78.         if(z==4)
  79.         {
  80.             d+=2;
  81.         }
  82.         for(int i=0; i<=a; i++)
  83.         {
  84.             cout<<" ";
  85.         }
  86.         cout<<"◆"<<endl;
  87.         
  88.         for(int i=0; i<=b; i++)
  89.         {
  90.             cout<<" ";
  91.         }
  92.         cout<<"★"<<endl;
  93.         
  94.         for(int i=0; i<=c; i++)
  95.         {
  96.             cout<<" ";
  97.         }
  98.         cout<<"㊣"<<endl;
  99.         
  100.         for(int i=0; i<=d; i++)
  101.         {
  102.             cout<<" ";
  103.         }
  104.         cout<<"▼"<<endl;
  105.         
  106.         system("cls");
  107.     }
  108.    
  109.     cout<<"第"<<x<<"場比賽結束   由";
  110.     if(a==70)
  111.     {
  112.        cout<<"◆";
  113.         win=1;
  114.     }else if(b==70)
  115.     {
  116.           cout<<"★";
  117.         win=2;
  118.     }else if(c==70)
  119.     {
  120.           cout<<"㊣";
  121.         win=3;
  122.     }else
  123.     {
  124.          cout<<"▼";
  125.         win=4;
  126.     }
  127.     cout<<"先馳得點!"<<endl;
  128.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  129.    
  130.      for(int i=0; i<=a; i++)
  131.         {
  132.             cout<<" ";
  133.         }
  134.         cout<<"◆"<<endl;
  135.         
  136.         for(int i=0; i<=b; i++)
  137.         {
  138.             cout<<" ";
  139.         }
  140.         cout<<"★"<<endl;
  141.         
  142.         for(int i=0; i<=c; i++)
  143.         {
  144.             cout<<" ";
  145.         }
  146.         cout<<"㊣"<<endl;
  147.         
  148.         for(int i=0; i<=d; i++)
  149.         {
  150.             cout<<" ";
  151.         }
  152.         cout<<"▼"<<endl;
  153.         
  154.         cout<<"按任意鍵進行下一場比賽"<<endl;
  155.         if(win=many)
  156.         {
  157.             mony=mony+bird*3;
  158.         }else
  159.         {
  160.             mony=mony-bird;
  161.         }
  162.         system("pause");
  163.         system("cls");
  164.         x++;
  165.         goto re;
  166.         go:
  167.     system("pause");
  168.     return 0;
  169. }
複製代碼

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int n=1,money=0;
  8.     re1:
  9.     int a=0, b=0, c=0, d=0, r,option,winner,bet,buying;
  10.     system("cls");
  11.     cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
  12.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  13.     cout<<"◆"<<endl;
  14.     cout<<"★"<<endl;
  15.     cout<<"▲"<<endl;
  16.     cout<<"●"<<endl<<endl;
  17.     cout<<"可用餘額: "<< money<<"元"<<endl<<endl;
  18.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  19.     cin>>option;
  20.     if(option==1)  //選擇買入多少籌碼
  21.     {
  22.        cout<<"買入:";
  23.        cin>>buying;
  24.        money = money + buying; // 原始的餘額加上買入的籌碼
  25.        goto re1;
  26.     }else if(option==2)
  27.     {
  28.        if(money==0)   //一開始就沒有餘額
  29.        {
  30.            cout<<"可用餘額不足!請先買入!"<<endl;
  31.            system("pause");
  32.            goto re1;
  33.        }
  34.       
  35.         cout<<"下注:";
  36.         cin>> bet;
  37.         if(bet>money)   //餘額< 下注金額
  38.         {
  39.            cout<<"可用餘額不足!請先買入!"<<endl;
  40.            system("pause");
  41.            goto re1;
  42.         }else
  43.         {
  44.              cout<<"(1)◆(2)★(3)▲(4)● 請選擇: "<<endl;
  45.              cin>>option;
  46.             cout<<"比賽即將開始..."<<endl<<endl;
  47.             system("pause");   
  48.         }
  49.         
  50.     }else if(option==3)
  51.     {
  52.           goto end;
  53.     }else
  54.     {
  55.          cout<<"輸入錯誤!!"<<endl;
  56.           system("pause");
  57.          goto re1;
  58.     }
  59.    
  60.    
  61.     system("pause");
  62.     system("cls");
  63.     srand(time(NULL));
  64.     while(a!=75 && b!=75 && c!=75 && d!=75)
  65.     {
  66.         r=rand()%4;   //產生0~3之隨機亂數
  67.         if(r==0)
  68.             a++;
  69.         else if(r==1)
  70.             b++;
  71.         else if(r==2)
  72.             c++;
  73.         else
  74.             d++;
  75.         cout<<"比賽進行中"<<endl;
  76.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  77.         for(int i=1; i<=a; i++)
  78.             cout<<" ";
  79.         cout<<"◆"<<endl;
  80.         
  81.         for(int i=1; i<=b; i++)
  82.             cout<<" ";
  83.         cout<<"★"<<endl;
  84.         
  85.         for(int i=1; i<=c; i++)
  86.             cout<<" ";
  87.         cout<<"▲"<<endl;
  88.         
  89.         for(int i=1; i<=d; i++)
  90.             cout<<" ";
  91.         cout<<"●"<<endl;   
  92.         system("cls");      
  93.     }
  94.     // 比賽結束時 第一名的馬
  95.     cout<<"比賽結束! 由 ";
  96.     if(a==75)
  97.         {
  98.            cout<<"◆";
  99.            winner+1;         
  100.         }
  101.     else if(b==75)
  102.         {
  103.            cout<<"★";
  104.            winner+1;
  105.         }
  106.     else if(c==75)
  107.         {
  108.            cout<<"▲";
  109.            winner+1;
  110.         }
  111.     else
  112.         {
  113.            cout<<"●";
  114.            winner+1;
  115.         }
  116.     cout<<" 先馳得點!"<<endl;
  117.     // 印出最後4匹馬的結果
  118.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  119.     for(int i=1; i<=a; i++)
  120.         cout<<" ";
  121.     cout<<"◆"<<endl;
  122.    
  123.     for(int i=1; i<=b; i++)
  124.         cout<<" ";
  125.     cout<<"★"<<endl;
  126.    
  127.     for(int i=1; i<=c; i++)
  128.         cout<<" ";
  129.     cout<<"▲"<<endl;
  130.    
  131.     for(int i=1; i<=d; i++)
  132.         cout<<" ";
  133.     cout<<"●"<<endl;
  134.     if(winner==option)
  135.     {
  136.         money = money+ bet*3;
  137.     }else
  138.     {   
  139.         money = money - bet ;         
  140.     }
  141.     system("pause");
  142.    
  143.     n++;
  144.     goto re1;
  145.     end:
  146.     system("pause");
  147.     return 0;   
  148. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0;
  7.     start:
  8.     srand(time(NULL));
  9.     int space[]={0,0,0,0};
  10.     int option, money, winer, bet;
  11.     system("cls");
  12.     cout<<"賽馬場"<<endl;
  13.     cout<<"------------------------------------------------------------------------------| 終點"<<endl;
  14.     cout<<"◆"<<endl;
  15.     cout<<"★"<<endl;
  16.     cout<<"▲"<<endl;
  17.     cout<<"●"<<endl;
  18.     cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  19.     cout<<"(1)買入  (2)下注  (3)離開  請選擇: ";
  20.     cin>>option;
  21.    
  22.     if (option==1)
  23.     {    cout<<"買入: ";
  24.         cin>>money;
  25.         balance+=money;
  26.         goto start;
  27.     }

  28.     cout<<"下注:";
  29.     cin>>bet;
  30.     if (bet>money)
  31.     {
  32.             cout<<"可用餘額不足!請先買入"<<endl;
  33.            system("pause");
  34.            goto start;
  35.            }else
  36.            {
  37.                  cout<<"(1)◆ (2)★ (3)▲ (4)●請選擇: "<<endl;
  38.                  cin>>option;
  39.                  
  40.            }
  41.     system("pause");
  42.     while (true)
  43.     {
  44.           int r=rand()%4;
  45.           space[r]++;
  46.           if(space[r]==74)
  47.                break;
  48.           cout<<"比賽進行中"<<endl;
  49.           cout<<"--------------------------------------------------------------------------| 終點"<<endl;
  50.              for(int i=0;i<=space[0];i++)
  51.              {
  52.                   cout<<" ";
  53.              }
  54.              cout<<"◆"<<endl;
  55.              for(int j=0;j<=space[1]; j++)
  56.              {
  57.                   cout<<" ";
  58.              }
  59.              cout<<"★"<<endl;
  60.              for(int j=0;j<=space[2];j++)
  61.              {
  62.                   cout<<" ";
  63.              }
  64.              cout<<"▲"<<endl;
  65.              for(int j=0;j<=space[3];j++)
  66.              {     
  67.                    cout<<" ";
  68.              }
  69.              cout<<"●"<<endl;
  70.              system("cls");
  71.      }
  72.          cout<<"比賽結束! 由 ";
  73.     if(space[0]==74)
  74.     {
  75.         cout<<"◆";
  76.         winer =1;
  77.     }
  78.     else if(space[1]==74)
  79.     {
  80.         cout<<"★";
  81.         winer =2;
  82.     }
  83.     else if(space[2]==74)
  84.     {
  85.         cout<<"▲";
  86.         winer =3;
  87.     }
  88.     else
  89.     {
  90.         cout<<"●";
  91.         winer =4;
  92.     }
  93.     cout<<" 先到達終點!"<<endl;

  94.            cout<<"比賽結束"<<endl;
  95.           cout<<"--------------------------------------------------------------------------| 終點"<<endl;
  96.              for(int i=0;i<=space[0];i++)
  97.              {
  98.                   cout<<" ";
  99.              }
  100.              cout<<"◆"<<endl;
  101.              for(int j=0;j<=space[1]; j++)
  102.              {
  103.                   cout<<" ";
  104.              }
  105.              cout<<"★"<<endl;
  106.              for(int j=0;j<=space[2];j++)
  107.              {
  108.                   cout<<" ";
  109.              }
  110.              cout<<"▲"<<endl;
  111.              for(int j=0;j<=space[3];j++)
  112.              {     
  113.                    cout<<" ";
  114.              }
  115.              cout<<"●"<<endl;
  116.             
  117.              if (option==winer)
  118.              {
  119.               balance = balance+ bet*3;
  120.              }
  121.              else
  122.              {
  123.               balance = balance- bet;
  124.              }
  125.              system("pause");
  126.              goto start;
  127.     system("pause");
  128.     return 0;   
  129. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     int n=1,money=0;
  8.     re1:
  9.     int a=0, b=0, c=0, d=0, r,option,winer,buying,bet;
  10.     system("cls");
  11.     cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
  12.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  13.     cout<<"◆"<<endl;
  14.     cout<<"★"<<endl;
  15.     cout<<"▲"<<endl;
  16.     cout<<"●"<<endl<<endl;
  17.     cout<<"可用餘額: "<< money<<"元"<<endl<<endl;
  18.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  19.     cin>>option;
  20.     if(option==1)  //選擇買入多少籌碼
  21.     {
  22.       
  23.        cout<<"買入:";
  24.        cin>>buying;
  25.        money = money + buying; // 原始的餘額加上買入的籌碼
  26.        goto re1;
  27.     }else if(option==2)
  28.     {
  29.        if(money==0)   //一開始就沒有餘額
  30.        {
  31.            cout<<"可用餘額不足!請先買入!"<<endl;
  32.            system("pause");
  33.            goto re1;
  34.        }
  35.       
  36.      
  37.         cout<<"下注:";
  38.         cin>> bet;
  39.         if(bet>money)   //餘額< 下注金額
  40.         {
  41.            cout<<"可用餘額不足!請先買入!"<<endl;
  42.            system("pause");
  43.            goto re1;
  44.         }else
  45.         {
  46.              dog:
  47.              cout<<"(1)◆(2)★(3)▲(4)● 請選擇: "<<endl;
  48.              cin>>option;
  49.              if(option>4)
  50.              {
  51.                          cout<<"你選錯了"<<endl;
  52.                           system("pause");  
  53.                           goto dog;
  54.              }
  55.             cout<<"比賽即將開始..."<<endl<<endl;
  56.             system("pause");   
  57.         }
  58.         
  59.     }else if(option==3)
  60.     {
  61.           goto end;
  62.     }else
  63.     {
  64.          cout<<"輸入錯誤!!"<<endl;
  65.           system("pause");
  66.          goto re1;
  67.     }
  68.    
  69.    
  70.     system("cls");
  71.     srand(time(NULL));
  72.     while(a!=75 && b!=75 && c!=75 && d!=75)
  73.     {
  74.         r=rand()%4;   //產生0~3之隨機亂數
  75.         if(r==0)
  76.             a++;
  77.         else if(r==1)
  78.             b++;
  79.         else if(r==2)
  80.             c++;
  81.         else
  82.             d++;
  83.         cout<<"比賽進行中"<<endl;
  84.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  85.         for(int i=1; i<=a; i++)
  86.             cout<<" ";
  87.         cout<<"◆"<<endl;
  88.         
  89.         for(int i=1; i<=b; i++)
  90.             cout<<" ";
  91.         cout<<"★"<<endl;
  92.         
  93.         for(int i=1; i<=c; i++)
  94.             cout<<" ";
  95.         cout<<"▲"<<endl;
  96.         
  97.         for(int i=1; i<=d; i++)
  98.             cout<<" ";
  99.         cout<<"●"<<endl;   
  100.         system("cls");      
  101.     }
  102.     // 比賽結束時 第一名的馬
  103.     cout<<"比賽結束! 由 ";
  104.     if(a==75)
  105.     {
  106.          cout<<"◆";
  107.          winer=1;
  108.     }   
  109.     else if(b==75)
  110.     {
  111.          cout<<"★";
  112.          winer=2;
  113.     }
  114.     else if(c==75)
  115.     {
  116.          cout<<"▲";
  117.          winer=3;
  118.     }
  119.         
  120.     else
  121.     {
  122.          cout<<"●";
  123.          winer=4;
  124.     }

  125.     cout<<" 先馳得點!"<<endl;
  126.     // 印出最後4匹馬的結果
  127.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  128.     for(int i=1; i<=a; i++)
  129.         cout<<" ";
  130.     cout<<"◆"<<endl;
  131.    
  132.     for(int i=1; i<=b; i++)
  133.         cout<<" ";
  134.     cout<<"★"<<endl;
  135.    
  136.     for(int i=1; i<=c; i++)
  137.         cout<<" ";
  138.     cout<<"▲"<<endl;
  139.    
  140.     for(int i=1; i<=d; i++)
  141.         cout<<" ";
  142.     cout<<"●"<<endl;
  143.      if(winer==option)
  144.     {
  145.                      money=money+bet*3;
  146.     }else
  147.     {
  148.                     money=money-bet;
  149.     }
  150.    
  151.     system("pause");
  152.    
  153.     n++;
  154.     goto re1;
  155.     end:
  156.     system("pause");
  157.     return 0;   
  158. }
複製代碼

TOP

返回列表