返回列表 發帖

賽馬程式 (七)& 優化程式

本帖最後由 陳品肇 於 2022-4-2 11:45 編輯

完成選項 (3)離開 的相對應程式碼
在離開時顯示戰果, 譬如:
"沒輸沒贏! 全身而退!"
"恭喜你! 這次總共贏了100元!"
"不好意思! 讓你損失了200元!"
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     // 開局第一場
  8.     // money 拿來作為輸贏的統計
  9.     int n =1,blance=0,money=0;
  10.     re:   
  11.     system("cls");
  12.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  13.    
  14.     string words ="賽馬進行中";
  15.     // 代表馬的名子
  16.     string name[4] = {"◆","★","▲","●"};
  17.    
  18.     // 宣告一個暫存的變數
  19.     int position =0;
  20.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  21.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  22.     cout<<"◆"<<endl;
  23.     cout<<"★"<<endl;
  24.     cout<<"▲"<<endl;
  25.     cout<<"●"<<endl;
  26.     cout<<endl;
  27.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  28.     cout<<endl;
  29.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  30.     cin>>option;
  31.    
  32.     // 如果買入 把錢加入餘額
  33.     if(option==1)
  34.     {
  35.         cout<<"買入:";
  36.         cin>>buyin;
  37.         blance += buyin;
  38.         goto re;
  39.     }else if(option==2)
  40.     {
  41.         cout<<"請下注:";
  42.         cin>>bet;
  43.         if(bet > blance)
  44.         {
  45.            cout<<"您餘額不足,請重新下注!"<<endl;            
  46.            system("pause");
  47.            goto re;
  48.         }else if(bet >0 && bet<=blance)
  49.         {
  50.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  51.            cin>>horse;
  52.            blance -= bet;
  53.            cout<<"即將開始賽馬!"<<endl;
  54.         }else
  55.         {
  56.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  57.            system("pause");
  58.            goto re;
  59.         }
  60.         
  61.     }else
  62.     {
  63.        // 離開      
  64.         goto end;
  65.     }
  66.    
  67.     system("pause"); // 按下enter 才開始
  68.     system("cls"); // 清空畫面
  69.     srand(time(NULL)); // 撒種子亂數
  70.   
  71.     // 當有任一匹跑到終點70 的時候就跳離迴圈
  72.     while(a<70 && b<70 && c<70 && d<70)
  73.     {  
  74.    
  75.       // 隨機挑一匹馬
  76.       r = rand()%4+1;
  77.       // 每匹馬 跑的進度
  78.       switch(r)
  79.       {
  80.           case 1:
  81.                a++;
  82.                break;
  83.           case 2:
  84.                b++;
  85.                break;
  86.           case 3:
  87.                c++;
  88.                break;
  89.           case 4:
  90.                d++;
  91.                break;
  92.       }
  93.       
  94.    
  95.       if(a==70 || b==70 || c==70 || d==70)
  96.       {  
  97.          if(a==70)
  98.          {         
  99.               position = 0;
  100.               winer = 1;
  101.          }
  102.          if(b==70)
  103.          {         
  104.               position =1;
  105.               winer = 2;
  106.          }
  107.          if(c==70)
  108.          {         
  109.               position =2;
  110.               winer = 3;
  111.          }
  112.          if(d==70)
  113.          {         
  114.               position =3;
  115.               winer =4;
  116.          }         
  117.          
  118.          words = "比賽結束!由"+name[position]+"先馳得點!";
  119.       }
  120.       
  121.       cout<<words<<endl;
  122.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  123.       
  124.       // 要把每匹馬的進度給輸出
  125.       // 第一匹馬
  126.       for(int i=0;i<=a;i++)
  127.       {
  128.           cout<<" ";
  129.       }
  130.       cout<<name[0]<<endl;
  131.       
  132.       // 第二匹馬
  133.       for(int i=0;i<=b;i++)
  134.       {
  135.           cout<<" ";
  136.       }
  137.       cout<<name[1]<<endl;
  138.       
  139.        // 第三匹馬
  140.       for(int i=0;i<=c;i++)
  141.       {
  142.           cout<<" ";
  143.       }
  144.       cout<<name[2]<<endl;
  145.       
  146.       // 第四匹馬
  147.       for(int i=0;i<=d;i++)
  148.       {
  149.           cout<<" ";
  150.       }
  151.       cout<<name[3]<<endl;
  152.       
  153.       
  154.       //還沒有任一匹馬到終點 要清空畫面
  155.       if(a<=69 && b<=69 && c<=69 && d<=69)
  156.       {           
  157.         system("cls"); // 清空畫面
  158.       }
  159.       
  160.     }
  161.    
  162.     // 如果選的馬 = 最終跑贏的結果
  163.     if(horse == winer)
  164.     {
  165.         // 現有的錢 + 投注的錢*3
  166.         blance = blance + bet*3;
  167.         // 把贏的錢做統計
  168.         money = money + bet*3;
  169.         cout<<"您贏了"<<bet*3<<"元"<<endl;
  170.     }else
  171.     {
  172.         // 把輸的錢做統計
  173.         money = money -bet;
  174.         cout<<"損失"<<bet<<"元"<<endl;
  175.     }
  176.    
  177.     // 局數+1  
  178.     n++;
  179.     system("pause");
  180.     goto re;     
  181.     end:
  182.    
  183.     if(money ==0 )
  184.     {
  185.        cout<<"沒輸沒贏! 全身而退!"<<endl;
  186.     }else if( money > 0)
  187.     {
  188.        cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
  189.     }else
  190.     {
  191.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
  192.     }
  193.     cout<<endl;
  194.     cout<<"謝謝光臨! 下次再來!"<<endl;
  195.     system("pause");  
  196.     return 0;   
  197. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n =1,blance=0,totalbuy=0;
  8.     re:   
  9.     system("cls");
  10.     int a=0,b=0,c=0,d=0,r, option, buyin =0 ,pay ,choose ;
  11.     string words ="賽馬進行中";
  12.     string name[4] = {"◆","★","▲","●"};
  13.     int position =0;
  14.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  15.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  16.     cout<<"◆"<<endl;
  17.     cout<<"★"<<endl;
  18.     cout<<"▲"<<endl;
  19.     cout<<"●"<<endl;
  20.     cout<<endl;
  21.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  22.     cout<<endl;
  23.     back:
  24.     cout<<"(1)買入 (2)下注 (3)離開  請選擇:";
  25.     cin>>option;
  26.     if(option==1)
  27.     {
  28.         cout<<"買入:";
  29.         cin>>buyin;
  30.         blance += buyin;
  31.         totalbuy += buyin;
  32.         goto re;
  33.     }else if(option==2)
  34.     {
  35.         cout<<"請下注:";
  36.         cin>>pay;
  37.         if(pay>blance)
  38.         {
  39.             cout<<"您餘額不足,請重新下注"<<endl;
  40.             system("pause");
  41.             goto back;
  42.         }
  43.         if(pay<=0)
  44.         {
  45.             cout<<"輸入錯誤"<<endl;
  46.             goto back;
  47.         }
  48.         cout<<"(1)◆ (2)★ (3)▲ (4)●請選擇:";
  49.         cin>>choose;
  50.         if(choose==1)
  51.         {      
  52.         }else if(choose==2)
  53.         {      
  54.         }else if(choose==3)
  55.         {      
  56.         }else if(choose==4)
  57.         {      
  58.         }else if(choose==5)
  59.         {
  60.             goto back;
  61.         }else{
  62.             cout<<"輸入錯誤"<<endl;
  63.             goto back;
  64.         }
  65.         blance-=pay;
  66.     }else if(option==3)
  67.     {
  68.         goto end;
  69.     }else{
  70.         cout<<"輸入錯誤"<<endl;
  71.         goto back;
  72.     }
  73.     play:
  74.     system("pause");
  75.     system("cls");
  76.     srand(time(NULL));
  77.     while(a<=70 && b<=70 && c<=70 && d<=70)
  78.     {  
  79.         cout<<words<<endl;
  80.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  81.         if(a==70)
  82.         {
  83.             a++;
  84.             goto over;
  85.         }
  86.         if(b==70)
  87.         {
  88.             b++;
  89.             goto over;
  90.         }
  91.         if(c==70)
  92.         {
  93.             c++;
  94.             goto over;
  95.         }  
  96.         if(d==70)
  97.         {
  98.             d++;
  99.             goto over;
  100.         }   
  101.         r = rand()%4+1;
  102.         switch(r)
  103.         {
  104.             case 1:
  105.                 a++;
  106.                 break;
  107.             case 2:
  108.                 b++;
  109.                 break;
  110.             case 3:
  111.                 c++;
  112.                 break;
  113.             case 4:
  114.                 d++;
  115.                 break;
  116.         }
  117.         over:
  118.         for(int i=0;i<=a;i++)
  119.         {
  120.             cout<<" ";
  121.         }
  122.         cout<<name[0]<<endl;
  123.         for(int i=0;i<=b;i++)
  124.         {
  125.             cout<<" ";
  126.         }
  127.         cout<<name[1]<<endl;
  128.         for(int i=0;i<=c;i++)
  129.         {
  130.             cout<<" ";
  131.         }
  132.         cout<<name[2]<<endl;
  133.         for(int i=0;i<=d;i++)
  134.         {
  135.             cout<<" ";
  136.         }
  137.         cout<<name[3]<<endl;
  138.         if(a==70 || b==70 || c==70 || d==70)
  139.         {  
  140.             if(a==70)
  141.                 position = 0;
  142.             if(b==70)
  143.                 position =1;
  144.             if(c==70)
  145.                 position =2;
  146.             if(d==70)
  147.                 position =3;
  148.             words = "比賽結束!由"+name[position]+"先馳得點!";
  149.         }
  150.         if(a==71 || b==71 || c==71 || d==71)
  151.         {      
  152.             if(option==3)
  153.                 goto keep;
  154.             if(position==0)
  155.             {      
  156.                 if(choose==1)
  157.                 {
  158.                     cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  159.                     blance+=3*pay;
  160.                 }else{
  161.                     cout<<"可惜,你輸了,再接再厲"<<endl;
  162.                 }
  163.             }else if(position==1)
  164.             {
  165.                                 if(choose==2)
  166.                 {
  167.                     cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  168.                     blance+=3*pay;
  169.                 }else{
  170.                     cout<<"可惜,你輸了,再接再厲"<<endl;
  171.                 }
  172.             }else if(position==2)
  173.             {      
  174.                 if(choose==3)
  175.                 {
  176.                     cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  177.                     blance+=3*pay;
  178.                 }else{
  179.                     cout<<"可惜,你輸了,再接再厲"<<endl;
  180.                 }
  181.                 }else if(position==3)
  182.                 {      
  183.                     if(choose==4)
  184.                     {
  185.                         cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  186.                         blance+=3*pay;
  187.                     }else{
  188.                         cout<<"可惜,你輸了,再接再厲"<<endl;
  189.                     }
  190.                 }      
  191.                 }else{      
  192.                     system("cls");
  193.                 }
  194.             }
  195.     keep:
  196.     n++;
  197.     system("pause");
  198.     goto re;
  199.     end:
  200.     if(blance==totalbuy)
  201.     {
  202.         cout<<"沒輸沒贏! 全身而退!"<<endl;
  203.     }else if(blance>totalbuy)
  204.     {
  205.         cout<<"恭喜你! 這次總共贏了"<<blance-totalbuy<<"元!"<<endl;
  206.     }else if(blance<totalbuy)
  207.     {
  208.         cout<<"不好意思! 讓你損失了"<<totalbuy-blance<<"元!"<<endl;
  209.     }
  210.     system("pause");
  211.     return 0;   
  212. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n =1,blance=0,totalbuy=0;
  8.     re:   
  9.     system("cls");
  10.     int a=0,b=0,c=0,d=0,r, option, buyin =0 ,pay ,choose ;
  11.     string words ="賽馬進行中";
  12.     string name[4] = {"◆","★","▲","●"};
  13.     int position =0;
  14.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  15.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  16.     cout<<"◆"<<endl;
  17.     cout<<"★"<<endl;
  18.     cout<<"▲"<<endl;
  19.     cout<<"●"<<endl;
  20.     cout<<endl;
  21.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  22.     cout<<endl;
  23.     back:
  24.     cout<<"(1)買入 (2)下注 (3)純粹觀賽  (4)離開  請選擇:";
  25.     cin>>option;
  26.     if(option==1)
  27.     {
  28.         cout<<"買入:";
  29.         cin>>buyin;
  30.         blance += buyin;
  31.         totalbuy += buyin;
  32.         goto re;
  33.     }else if(option==2)
  34.     {
  35.         cout<<"請下注:";
  36.         cin>>pay;
  37.         if(pay>blance)
  38.         {
  39.             cout<<"您餘額不足,請重新下注"<<endl;
  40.             system("pause");
  41.             goto back;
  42.         }
  43.         if(pay<=0)
  44.         {
  45.             cout<<"輸入錯誤"<<endl;
  46.             goto back;
  47.         }
  48.         cout<<"(1)◆ (2)★ (3)▲ (4)● (5)離開  請選擇:";
  49.         cin>>choose;
  50.         if(choose==1)
  51.         {      
  52.         }else if(choose==2)
  53.         {      
  54.         }else if(choose==3)
  55.         {      
  56.         }else if(choose==4)
  57.         {      
  58.         }else if(choose==5)
  59.         {
  60.             goto back;
  61.         }else{
  62.             cout<<"輸入錯誤"<<endl;
  63.             goto back;
  64.         }
  65.         blance-=pay;
  66.     }else if(option==3)
  67.     {
  68.         goto play;
  69.     }else if(option==4)
  70.     {
  71.         goto end;
  72.     }else{
  73.         cout<<"輸入錯誤"<<endl;
  74.         goto back;
  75.     }
  76.     play:
  77.     system("pause");
  78.     system("cls");
  79.     srand(time(NULL));
  80.     while(a<=70 && b<=70 && c<=70 && d<=70)
  81.     {  
  82.         cout<<words<<endl;
  83.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  84.         if(a==70)
  85.         {
  86.             a++;
  87.             goto over;
  88.         }
  89.         if(b==70)
  90.         {
  91.             b++;
  92.             goto over;
  93.         }
  94.         if(c==70)
  95.         {
  96.             c++;
  97.             goto over;
  98.         }  
  99.         if(d==70)
  100.         {
  101.             d++;
  102.             goto over;
  103.         }   
  104.         r = rand()%4+1;
  105.         switch(r)
  106.         {
  107.             case 1:
  108.                 a++;
  109.                 break;
  110.             case 2:
  111.                 b++;
  112.                 break;
  113.             case 3:
  114.                 c++;
  115.                 break;
  116.             case 4:
  117.                 d++;
  118.                 break;
  119.         }
  120.         over:
  121.         for(int i=0;i<=a;i++)
  122.         {
  123.             cout<<" ";
  124.         }
  125.         cout<<name[0]<<endl;
  126.         for(int i=0;i<=b;i++)
  127.         {
  128.             cout<<" ";
  129.         }
  130.         cout<<name[1]<<endl;
  131.         for(int i=0;i<=c;i++)
  132.         {
  133.             cout<<" ";
  134.         }
  135.         cout<<name[2]<<endl;
  136.         for(int i=0;i<=d;i++)
  137.         {
  138.             cout<<" ";
  139.         }
  140.         cout<<name[3]<<endl;
  141.         if(a==70 || b==70 || c==70 || d==70)
  142.         {  
  143.             if(a==70)
  144.                 position = 0;
  145.             if(b==70)
  146.                 position =1;
  147.             if(c==70)
  148.                 position =2;
  149.             if(d==70)
  150.                 position =3;
  151.             words = "比賽結束!由"+name[position]+"先馳得點!";
  152.         }
  153.         if(a==71 || b==71 || c==71 || d==71)
  154.         {      
  155.             if(option==3)
  156.                 goto keep;
  157.             if(position==0)
  158.             {      
  159.                 if(choose==1)
  160.                 {
  161.                     cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  162.                     blance+=3*pay;
  163.                 }else{
  164.                     cout<<"可惜,你輸了,再接再厲"<<endl;
  165.                 }
  166.             }else if(position==1)
  167.             {
  168.                                 if(choose==2)
  169.                 {
  170.                     cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  171.                     blance+=3*pay;
  172.                 }else{
  173.                     cout<<"可惜,你輸了,再接再厲"<<endl;
  174.                 }
  175.             }else if(position==2)
  176.             {      
  177.                 if(choose==3)
  178.                 {
  179.                     cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  180.                     blance+=3*pay;
  181.                 }else{
  182.                     cout<<"可惜,你輸了,再接再厲"<<endl;
  183.                 }
  184.                 }else if(position==3)
  185.                 {      
  186.                     if(choose==4)
  187.                     {
  188.                         cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
  189.                         blance+=3*pay;
  190.                     }else{
  191.                         cout<<"可惜,你輸了,再接再厲"<<endl;
  192.                     }
  193.                 }      
  194.                 }else{      
  195.                     system("cls");
  196.                 }
  197.             }
  198.     keep:
  199.     n++;
  200.     system("pause");
  201.     goto re;
  202.     end:
  203.     if(blance==totalbuy)
  204.     {
  205.         cout<<"沒輸沒贏! 全身而退!"<<endl;
  206.     }else if(blance>totalbuy)
  207.     {
  208.         cout<<"恭喜你! 這次總共贏了"<<blance-totalbuy<<"元!"<<endl;
  209.     }else if(blance<totalbuy)
  210.     {
  211.         cout<<"不好意思! 讓你損失了"<<totalbuy-blance<<"元!"<<endl;
  212.     }
  213.     system("pause");
  214.     return 0;   
  215. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     // 開局第一場
  8.     int n =1,x=0,money=0;
  9.     re:   
  10.     system("cls");
  11.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  12.     string words ="賽馬進行中";
  13.     // 代表馬的名子
  14.     string name[4] = {"◆","★","▲","●"};
  15.    
  16.     // 宣告一個暫存的變數
  17.     int position =0;
  18.     cout<<"「智慧」賽馬場 第"<<n<<"局"<<endl;
  19.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  20.     cout<<"◆"<<endl;
  21.     cout<<"★"<<endl;
  22.     cout<<"▲"<<endl;
  23.     cout<<"●"<<endl;
  24.     cout<<endl;
  25.     cout<<"可用餘額:"<<x<<"元"<<endl;
  26.     cout<<endl;
  27.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  28.     cin>>option;
  29.    
  30.     // 如果買入 把錢加入餘額
  31.     if(option==1)
  32.     {
  33.         cout<<"買入:";
  34.         cin>>buyin;
  35.        x += buyin;
  36.         goto re;
  37.     }else if(option==2)
  38.     {
  39.         cout<<"請下注:";
  40.         cin>>bet;
  41.         if(bet > x)
  42.         {
  43.            cout<<"您餘額不足,請重新下注!"<<endl;            
  44.            system("pause");
  45.            goto re;
  46.         }else if(bet >0 && bet<=x)
  47.         {
  48.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  49.            cin>>horse;
  50.            x -= bet;
  51.            cout<<"即將開始賽馬!"<<endl;
  52.         }else
  53.         {
  54.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  55.            system("pause");
  56.            goto re;
  57.         }
  58.         
  59.     }else
  60.     {
  61.        // 離開      
  62.         goto end;
  63.     }
  64.    
  65.     system("pause"); // 按下enter 才開始
  66.     system("cls"); // 清空畫面
  67.     srand(time(NULL)); // 撒種子亂數
  68.   
  69.     while(a<70 && b<70 && c<70 && d<70)
  70.     {  
  71.       
  72.       // 隨機挑一匹馬
  73.       r = rand()%4+1;
  74.       // 每匹馬 跑的進度
  75.       switch(r)
  76.       {
  77.           case 1:
  78.                a++;
  79.                break;
  80.           case 2:
  81.                b++;
  82.                break;
  83.           case 3:
  84.                c++;
  85.                break;
  86.           case 4:
  87.                d++;
  88.                break;
  89.       }
  90.       if(a==70 || b==70 || c==70 || d==70)
  91.       {  
  92.          if(a==70)
  93.          {
  94.              position = 0;
  95.              winer = 1;   
  96.          }
  97.               
  98.          if(b==70)
  99.          {
  100.               position =1;
  101.               winer = 2;   
  102.          }
  103.          
  104.          if(c==70)
  105.          {
  106.               position =2;
  107.               winer = 3;   
  108.          }
  109.               
  110.          if(d==70)
  111.          {
  112.               position =3;
  113.               winer = 4;      
  114.          }           
  115.          
  116.          words = "比賽結束!由"+name[position]+"先馳得點!";
  117.       }
  118.       cout<<words<<endl;
  119.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  120.       
  121.       // 要把每匹馬的進度給輸出
  122.       // 第一匹馬
  123.       for(int i=0;i<=a;i++)
  124.       {
  125.           cout<<" ";
  126.       }
  127.       cout<<name[0]<<endl;
  128.       
  129.       // 第二匹馬
  130.       for(int i=0;i<=b;i++)
  131.       {
  132.           cout<<" ";
  133.       }
  134.       cout<<name[1]<<endl;
  135.       
  136.        // 第三匹馬
  137.       for(int i=0;i<=c;i++)
  138.       {
  139.           cout<<" ";
  140.       }
  141.       cout<<name[2]<<endl;
  142.       
  143.       // 第四匹馬
  144.       for(int i=0;i<=d;i++)
  145.       {
  146.           cout<<" ";
  147.       }
  148.       cout<<name[3]<<endl;
  149.       
  150.    
  151.       
  152.       if(a<=69 && b<=69 && c<=69 && d<=69)
  153.       {               
  154.             
  155.         system("cls");
  156.       }
  157.       
  158.     }
  159.     if(horse == winer)
  160.     {
  161.        x = x +bet*3;
  162.        money = money -bet;
  163.        cout<<"您贏了"<<bet*3<<"元"<<endl;      
  164.     }else
  165.     {
  166.         money = money -bet;
  167.         cout<<"損失"<<bet<<"元"<<endl;
  168.     }
  169.     n++;                  
  170.     system("pause");
  171.     goto re;
  172.     end:
  173.     if(money ==0)
  174.     {
  175.         cout<<"沒輸沒贏! 全身而退!"<<endl;
  176.     }else if(money > 0)
  177.     {
  178.         cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;  
  179.     }else
  180.     {
  181.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;  
  182.     }
  183.     system("pause");
  184.     return 0;   
  185. }
複製代碼

TOP

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

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n =1,blance=0,money=0;
  8.     re:   
  9.     system("cls");
  10.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  11.    
  12.     string words ="賽馬進行中";

  13.     string name[4] = {"◆","★","▲","●"};
  14.    
  15.     int position =0;
  16.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  17.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  18.     cout<<"◆"<<endl;
  19.     cout<<"★"<<endl;
  20.     cout<<"▲"<<endl;
  21.     cout<<"●"<<endl;
  22.     cout<<endl;
  23.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  24.     cout<<endl;
  25.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  26.     cin>>option;
  27.    
  28.     if(option==1)
  29.     {
  30.         cout<<"買入:";
  31.         cin>>buyin;
  32.         blance += buyin;
  33.         goto re;
  34.     }else if(option==2)
  35.     {
  36.         cout<<"請下注:";
  37.         cin>>bet;
  38.         if(bet > blance)
  39.         {
  40.            cout<<"您餘額不足,請重新下注!"<<endl;            
  41.            system("pause");
  42.            goto re;
  43.         }else if(bet >0 && bet<=blance)
  44.         {
  45.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  46.            cin>>horse;
  47.            blance -= bet;
  48.            cout<<"即將開始賽馬!"<<endl;
  49.         }else
  50.         {
  51.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  52.            system("pause");
  53.            goto re;
  54.         }
  55.         
  56.     }else
  57.     {   
  58.         goto end;
  59.     }
  60.    
  61.     system("pause");
  62.     system("cls");
  63.     srand(time(NULL));
  64.   
  65.     while(a<70 && b<70 && c<70 && d<70)
  66.     {  
  67.    
  68.       r = rand()%4+1;

  69.       switch(r)
  70.       {
  71.           case 1:
  72.                a++;
  73.                break;
  74.           case 2:
  75.                b++;
  76.                break;
  77.           case 3:
  78.                c++;
  79.                break;
  80.           case 4:
  81.                d++;
  82.                break;
  83.       }
  84.       
  85.    
  86.       if(a==70 || b==70 || c==70 || d==70)
  87.       {  
  88.          if(a==70)
  89.          {         
  90.               position = 0;
  91.               winer = 1;
  92.          }
  93.          if(b==70)
  94.          {         
  95.               position =1;
  96.               winer = 2;
  97.          }
  98.          if(c==70)
  99.          {         
  100.               position =2;
  101.               winer = 3;
  102.          }
  103.          if(d==70)
  104.          {         
  105.               position =3;
  106.               winer =4;
  107.          }         
  108.          
  109.          words = "比賽結束!由"+name[position]+"先馳得點!";
  110.       }
  111.       
  112.       cout<<words<<endl;
  113.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  114.       
  115.       for(int i=0;i<=a;i++)
  116.       {
  117.           cout<<" ";
  118.       }
  119.       cout<<name[0]<<endl;
  120.       
  121.       for(int i=0;i<=b;i++)
  122.       {
  123.           cout<<" ";
  124.       }
  125.       cout<<name[1]<<endl;
  126.       
  127.       for(int i=0;i<=c;i++)
  128.       {
  129.           cout<<" ";
  130.       }
  131.       cout<<name[2]<<endl;
  132.       
  133.       for(int i=0;i<=d;i++)
  134.       {
  135.           cout<<" ";
  136.       }
  137.       cout<<name[3]<<endl;
  138.       
  139.       if(a<=69 && b<=69 && c<=69 && d<=69)
  140.       {           
  141.         system("cls");
  142.       }
  143.       
  144.     }
  145.    
  146.     if(horse == winer)
  147.     {
  148.         blance = blance + bet*3;

  149.         money = money + bet*3;
  150.         cout<<"您贏了"<<bet*3<<"元"<<endl;
  151.     }else
  152.     {

  153.         money = money -bet;
  154.         cout<<"損失"<<bet<<"元"<<endl;
  155.     }
  156.   
  157.     n++;
  158.     system("pause");
  159.     goto re;     
  160.     end:
  161.    
  162.     if(money ==0 )
  163.     {
  164.        cout<<"沒輸沒贏! 全身而退!"<<endl;
  165.     }else if( money > 0)
  166.     {
  167.        cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
  168.     }else
  169.     {
  170.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
  171.     }
  172.     cout<<endl;
  173.     cout<<"謝謝光臨! 下次再來!"<<endl;
  174.     system("pause");  
  175.     return 0;   
  176. }
複製代碼

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     // 開局第一場
  8.     // money 拿來作為輸贏的統計
  9.     int n =1,blance=0,money=0;
  10.     re:   
  11.     system("cls");
  12.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  13.    
  14.     string words ="賽馬進行中";
  15.     // 代表馬的名子
  16.     string name[4] = {"◆","★","▲","●"};
  17.    
  18.     // 宣告一個暫存的變數
  19.     int position =0;
  20.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  21.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  22.     cout<<"◆"<<endl;
  23.     cout<<"★"<<endl;
  24.     cout<<"▲"<<endl;
  25.     cout<<"●"<<endl;
  26.     cout<<endl;
  27.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  28.     cout<<endl;
  29.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  30.     cin>>option;
  31.    
  32.     // 如果買入 把錢加入餘額
  33.     if(option==1)
  34.     {
  35.         cout<<"買入:";
  36.         cin>>buyin;
  37.         blance += buyin;
  38.         goto re;
  39.     }else if(option==2)
  40.     {
  41.         cout<<"請下注:";
  42.         cin>>bet;
  43.         if(bet > blance)
  44.         {
  45.            cout<<"您餘額不足,請重新下注!"<<endl;            
  46.            system("pause");
  47.            goto re;
  48.         }else if(bet >0 && bet<=blance)
  49.         {
  50.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  51.            cin>>horse;
  52.            blance -= bet;
  53.            cout<<"即將開始賽馬!"<<endl;
  54.         }else
  55.         {
  56.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  57.            system("pause");
  58.            goto re;
  59.         }
  60.         
  61.     }else
  62.     {
  63.        // 離開      
  64.         goto end;
  65.     }
  66.    
  67.     system("pause"); // 按下enter 才開始
  68.     system("cls"); // 清空畫面
  69.     srand(time(NULL)); // 撒種子亂數
  70.   
  71.     // 當有任一匹跑到終點70 的時候就跳離迴圈
  72.     while(a<70 && b<70 && c<70 && d<70)
  73.     {  
  74.    
  75.       // 隨機挑一匹馬
  76.       r = rand()%4+1;
  77.       // 每匹馬 跑的進度
  78.       switch(r)
  79.       {
  80.           case 1:
  81.                a++;
  82.                break;
  83.           case 2:
  84.                b++;
  85.                break;
  86.           case 3:
  87.                c++;
  88.                break;
  89.           case 4:
  90.                d++;
  91.                break;
  92.       }
  93.       
  94.    
  95.       if(a==70 || b==70 || c==70 || d==70)
  96.       {  
  97.          if(a==70)
  98.          {         
  99.               position = 0;
  100.               winer = 1;
  101.          }
  102.          if(b==70)
  103.          {         
  104.               position =1;
  105.               winer = 2;
  106.          }
  107.          if(c==70)
  108.          {         
  109.               position =2;
  110.               winer = 3;
  111.          }
  112.          if(d==70)
  113.          {         
  114.               position =3;
  115.               winer =4;
  116.          }         
  117.          
  118.          words = "比賽結束!由"+name[position]+"先馳得點!";
  119.       }
  120.       
  121.       cout<<words<<endl;
  122.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  123.       
  124.       // 要把每匹馬的進度給輸出
  125.       // 第一匹馬
  126.       for(int i=0;i<=a;i++)
  127.       {
  128.           cout<<" ";
  129.       }
  130.       cout<<name[0]<<endl;
  131.       
  132.       // 第二匹馬
  133.       for(int i=0;i<=b;i++)
  134.       {
  135.           cout<<" ";
  136.       }
  137.       cout<<name[1]<<endl;
  138.       
  139.        // 第三匹馬
  140.       for(int i=0;i<=c;i++)
  141.       {
  142.           cout<<" ";
  143.       }
  144.       cout<<name[2]<<endl;
  145.       
  146.       // 第四匹馬
  147.       for(int i=0;i<=d;i++)
  148.       {
  149.           cout<<" ";
  150.       }
  151.       cout<<name[3]<<endl;
  152.       
  153.       
  154.       //還沒有任一匹馬到終點 要清空畫面
  155.       if(a<=69 && b<=69 && c<=69 && d<=69)
  156.       {           
  157.         system("cls"); // 清空畫面
  158.       }
  159.       
  160.     }
  161.    
  162.     // 如果選的馬 = 最終跑贏的結果
  163.     if(horse == winer)
  164.     {
  165.         // 現有的錢 + 投注的錢*3
  166.         blance = blance + bet*3;
  167.         // 把贏的錢做統計
  168.         money = money + bet*3;
  169.         cout<<"您贏了"<<bet*3<<"元"<<endl;
  170.     }else
  171.     {
  172.         // 把輸的錢做統計
  173.         money = money -bet;
  174.         cout<<"損失"<<bet<<"元"<<endl;
  175.     }
  176.    
  177.     // 局數+1  
  178.     n++;
  179.     system("pause");
  180.     goto re;     
  181.     end:
  182.    
  183.     if(money ==0 )
  184.     {
  185.        cout<<"沒輸沒贏! 全身而退!"<<endl;
  186.     }else if( money > 0)
  187.     {
  188.        cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
  189.     }else
  190.     {
  191.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
  192.     }
  193.     cout<<endl;
  194.     cout<<"謝謝光臨! 下次再來!"<<endl;
  195.     system("pause");  
  196.     return 0;   
  197. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     // 開局第一場
  8.     int n =1,x=0,money=0;
  9.     re:   
  10.     system("cls");
  11.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  12.     string words ="賽馬進行中";
  13.     // 代表馬的名子
  14.     string name[4] = {"◆","★","▲","●"};
  15.    
  16.     // 宣告一個暫存的變數
  17.     int position =0;
  18.     cout<<"「智慧」賽馬場 第"<<n<<"局"<<endl;
  19.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  20.     cout<<"◆"<<endl;
  21.     cout<<"★"<<endl;
  22.     cout<<"▲"<<endl;
  23.     cout<<"●"<<endl;
  24.     cout<<endl;
  25.     cout<<"可用餘額:"<<x<<"元"<<endl;
  26.     cout<<endl;
  27.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  28.     cin>>option;
  29.    
  30.     // 如果買入 把錢加入餘額
  31.     if(option==1)
  32.     {
  33.         cout<<"買入:";
  34.         cin>>buyin;
  35.        x += buyin;
  36.         goto re;
  37.     }else if(option==2)
  38.     {
  39.         cout<<"請下注:";
  40.         cin>>bet;
  41.         if(bet > x)
  42.         {
  43.            cout<<"您餘額不足,請重新下注!"<<endl;            
  44.            system("pause");
  45.            goto re;
  46.         }else if(bet >0 && bet<=x)
  47.         {
  48.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  49.            cin>>horse;
  50.            x -= bet;
  51.            cout<<"即將開始賽馬!"<<endl;
  52.         }else
  53.         {
  54.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  55.            system("pause");
  56.            goto re;
  57.         }
  58.         
  59.     }else
  60.     {
  61.        // 離開      
  62.         goto end;
  63.     }
  64.    
  65.     system("pause"); // 按下enter 才開始
  66.     system("cls"); // 清空畫面
  67.     srand(time(NULL)); // 撒種子亂數
  68.   
  69.     while(a<70 && b<70 && c<70 && d<70)
  70.     {  
  71.       
  72.       // 隨機挑一匹馬
  73.       r = rand()%4+1;
  74.       // 每匹馬 跑的進度
  75.       switch(r)
  76.       {
  77.           case 1:
  78.                a++;
  79.                break;
  80.           case 2:
  81.                b++;
  82.                break;
  83.           case 3:
  84.                c++;
  85.                break;
  86.           case 4:
  87.                d++;
  88.                break;
  89.       }
  90.       if(a==70 || b==70 || c==70 || d==70)
  91.       {  
  92.          if(a==70)
  93.          {
  94.              position = 0;
  95.              winer = 1;   
  96.          }
  97.               
  98.          if(b==70)
  99.          {
  100.               position =1;
  101.               winer = 2;   
  102.          }
  103.          
  104.          if(c==70)
  105.          {
  106.               position =2;
  107.               winer = 3;   
  108.          }
  109.               
  110.          if(d==70)
  111.          {
  112.               position =3;
  113.               winer = 4;      
  114.          }           
  115.          
  116.          words = "比賽結束!由"+name[position]+"先馳得點!";
  117.       }
  118.       cout<<words<<endl;
  119.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  120.       
  121.       // 要把每匹馬的進度給輸出
  122.       // 第一匹馬
  123.       for(int i=0;i<=a;i++)
  124.       {
  125.           cout<<" ";
  126.       }
  127.       cout<<name[0]<<endl;
  128.       
  129.       // 第二匹馬
  130.       for(int i=0;i<=b;i++)
  131.       {
  132.           cout<<" ";
  133.       }
  134.       cout<<name[1]<<endl;
  135.       
  136.        // 第三匹馬
  137.       for(int i=0;i<=c;i++)
  138.       {
  139.           cout<<" ";
  140.       }
  141.       cout<<name[2]<<endl;
  142.       
  143.       // 第四匹馬
  144.       for(int i=0;i<=d;i++)
  145.       {
  146.           cout<<" ";
  147.       }
  148.       cout<<name[3]<<endl;
  149.       
  150.    
  151.       
  152.       if(a<=69 && b<=69 && c<=69 && d<=69)
  153.       {               
  154.             
  155.         system("cls");
  156.       }
  157.       
  158.     }
  159.     if(horse == winer)
  160.     {
  161.        x = x +bet*3;
  162.        money = money -bet;
  163.        cout<<"您贏了"<<bet*3<<"元"<<endl;      
  164.     }else
  165.     {
  166.         money = money -bet;
  167.         cout<<"損失"<<bet<<"元"<<endl;
  168.     }
  169.     n++;                  
  170.     system("pause");
  171.     goto re;
  172.     end:
  173.     if(money ==0)
  174.     {
  175.         cout<<"沒輸沒贏! 全身而退!"<<endl;
  176.     }else if(money > 0)
  177.     {
  178.         cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;  
  179.     }else
  180.     {
  181.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;  
  182.     }
  183.     system("pause");
  184.     return 0;   
  185. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int t=1,z=0,money=0;
  8.     re:
  9.     system("cls");  
  10.     int a=0,b=0,c=0,d=0,r,tmp=0,o,buy=0,bet,horse,winer;
  11.     string words ="賽馬進行中";
  12.     string name[4] = {"◆","★","▲","●"};
  13.     cout<<"「好事成雙」賽馬場"<<"第"<<t<<"局"<<endl;
  14.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  15.     cout<<"◆"<<endl;
  16.     cout<<"★"<<endl;
  17.     cout<<"▲"<<endl;
  18.     cout<<"●"<<endl<<endl;
  19.     cout<<"可用餘額:"<<z<<"元"<<endl<<endl;
  20.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";  
  21.     cin>>o;
  22.     if(o==1)
  23.     {
  24.         cout<<"買入:";
  25.         cin>>buy;
  26.         z += buy;
  27.         goto re;
  28.     }else if(o==2)
  29.     {
  30.         cout<<"請下注:";
  31.         cin>>bet;
  32.         if(bet > z)
  33.         {
  34.            cout<<"您餘額不足,請重新下注!"<<endl;
  35.         }else if(bet >0 && bet<=z)
  36.         {
  37.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  38.            cin>>horse;
  39.            z -= bet;
  40.            cout<<"即將開始賽馬!"<<endl;
  41.         }else
  42.         {
  43.            cout<<"您輸入錯誤,請重新下注!"<<endl;
  44.             system("pause");
  45.             goto re;
  46.         }
  47.     }else
  48.     {
  49.         goto end;
  50.     }
  51.     system("pause");
  52.     system("cls");
  53.     srand(time(NULL));
  54.     while(a<70 && b<70 && c<70 && d<70)
  55.     {
  56.         r = rand()%4+1;
  57.         switch(r)
  58.         {
  59.             case 1:
  60.                  a++;
  61.                  break;
  62.             case 2:
  63.                  b++;
  64.                  break;
  65.             case 3:
  66.                  c++;
  67.                  break;
  68.             case 4:
  69.                  d++;      
  70.         }
  71.         if(a==70 || b==70 || c==70 || d==70)
  72.         {
  73.             if(a==70)
  74.             {
  75.                 tmp = 0;
  76.                 winer = 1;         
  77.             }
  78.             if(b==70)
  79.             {
  80.                 tmp = 1;
  81.                 winer = 2;         
  82.             }
  83.             if(c==70)
  84.             {
  85.                 tmp = 2;
  86.                 winer = 3;         
  87.             }
  88.             if(d==70)
  89.             {
  90.                 tmp =3;
  91.                 winer = 4;         
  92.             }
  93.             words = "比賽結束!由"+name[tmp]+"先馳得點!";;        
  94.         }
  95.         cout<<words<<endl;   
  96.         cout<<"------------------------------------------------------------------------| 終點"<<endl;  
  97.         for(int i=0;i<=a;i++)
  98.         {
  99.             cout<<" ";        
  100.         }
  101.         cout<<name[0]<<endl;  
  102.         for(int i=0;i<=b;i++)
  103.         {
  104.             cout<<" ";        
  105.         }
  106.         cout<<name[1]<<endl;  
  107.         for(int i=0;i<=c;i++)
  108.         {
  109.             cout<<" ";        
  110.         }
  111.         cout<<name[2]<<endl;  
  112.         for(int i=0;i<=d;i++)
  113.         {
  114.             cout<<" ";        
  115.         }
  116.         cout<<name[3]<<endl;

  117.         if(a<=69 && b<=69 && c<=69 && d<=69)
  118.         {
  119.             system("cls");     
  120.         }
  121.     }
  122.         if(horse == winer)
  123.         {
  124.             z = z + bet*3;
  125.             cout<<"您贏了"<<bet*3<<"元"<<endl;
  126.             money = money + bet*3;
  127.         }else
  128.         {
  129.             cout<<"損失"<<bet<<"元"<<endl;
  130.             money = money - bet;
  131.         }   
  132.     system("pause");
  133.     t++;   
  134.     goto re;
  135.     end:
  136.     if(money ==0 )
  137.     {
  138.        cout<<"沒輸沒贏! 全身而退!"<<endl;
  139.     }else if( money > 0)
  140.     {
  141.        cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
  142.     }else
  143.     {
  144.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
  145.     }
  146.     system("pause");  
  147.     return 0;   
  148. }
複製代碼

TOP

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

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     // 開局第一場
  8.     // money 拿來作為輸贏的統計
  9.     int n =1,blance=0,money=0;
  10.     re:   
  11.     system("cls");
  12.     int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度   
  13.    
  14.     // 當有任一匹跑到終點70 的時候就跳離迴圈
  15.     string words ="賽馬進行中";
  16.     // 代表馬的名子
  17.     string name[4] = {"◆","★","▲","●"};
  18.    
  19.     // 宣告一個暫存的變數
  20.     int position =0;
  21.     cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
  22.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  23.     cout<<"◆"<<endl;
  24.     cout<<"★"<<endl;
  25.     cout<<"▲"<<endl;
  26.     cout<<"●"<<endl;
  27.     cout<<endl;
  28.     cout<<"可用餘額:"<<blance<<"元"<<endl;
  29.     cout<<endl;
  30.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  31.     cin>>option;
  32.    
  33.     // 如果買入 把錢加入餘額
  34.     if(option==1)
  35.     {
  36.         cout<<"買入:";
  37.         cin>>buyin;
  38.         blance += buyin;
  39.         goto re;
  40.     }else if(option==2)
  41.     {
  42.         cout<<"請下注:";
  43.         cin>>bet;
  44.         if(bet > blance)
  45.         {
  46.            cout<<"您餘額不足,請重新下注!"<<endl;            
  47.            system("pause");
  48.            goto re;
  49.         }else if(bet >0 && bet<=blance)
  50.         {
  51.            cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
  52.            cin>>horse;
  53.            blance -= bet;
  54.            cout<<"即將開始賽馬!"<<endl;
  55.         }else
  56.         {
  57.            cout<<"您輸入錯誤,請重新下注!"<<endl;            
  58.            system("pause");
  59.            goto re;
  60.         }
  61.         
  62.     }else
  63.     {
  64.        // 離開      
  65.         goto end;
  66.     }
  67.    
  68.     system("pause"); // 按下enter 才開始
  69.     system("cls"); // 清空畫面
  70.     srand(time(NULL)); // 撒種子亂數
  71.   
  72.     while(a<=70 && b<=70 && c<=70 && d<=70)
  73.     {  
  74.       cout<<words<<endl;
  75.       cout<<"------------------------------------------------------------------------| 終點"<<endl;   
  76.       // 隨機挑一匹馬
  77.       r = rand()%4+1;
  78.       // 每匹馬 跑的進度
  79.       switch(r)
  80.       {
  81.           case 1:
  82.                a++;
  83.                break;
  84.           case 2:
  85.                b++;
  86.                break;
  87.           case 3:
  88.                c++;
  89.                break;
  90.           case 4:
  91.                d++;
  92.                break;
  93.       }
  94.       
  95.       // 要把每匹馬的進度給輸出
  96.       // 第一匹馬
  97.       for(int i=0;i<=a;i++)
  98.       {
  99.           cout<<" ";
  100.       }
  101.       cout<<name[0]<<endl;
  102.       
  103.       // 第二匹馬
  104.       for(int i=0;i<=b;i++)
  105.       {
  106.           cout<<" ";
  107.       }
  108.       cout<<name[1]<<endl;
  109.       
  110.        // 第三匹馬
  111.       for(int i=0;i<=c;i++)
  112.       {
  113.           cout<<" ";
  114.       }
  115.       cout<<name[2]<<endl;
  116.       
  117.       // 第四匹馬
  118.       for(int i=0;i<=d;i++)
  119.       {
  120.           cout<<" ";
  121.       }
  122.       cout<<name[3]<<endl;
  123.       
  124.    
  125.       if(a==70 || b==70 || c==70 || d==70)
  126.       {  
  127.          if(a==70)
  128.          {         
  129.               position = 0;
  130.               winer = 1;
  131.          }
  132.          if(b==70)
  133.          {         
  134.               position =1;
  135.               winer = 2;
  136.          }
  137.          if(c==70)
  138.          {         
  139.               position =2;
  140.               winer = 3;
  141.          }
  142.          if(d==70)
  143.          {         
  144.               position =3;
  145.               winer =4;
  146.          }         
  147.          
  148.          words = "比賽結束!由"+name[position]+"先馳得點!";
  149.       }
  150.       // 當有任一個跑到71 就代表到終點 不要清空畫面
  151.       if(a==71 || b==71 || c==71 || d==71)
  152.       {               
  153.       }else{      
  154.         system("cls"); // 清空畫面
  155.       }
  156.       
  157.     }
  158.    
  159.     // 如果選的馬 = 最終跑贏的結果
  160.     if(horse == winer)
  161.     {
  162.         // 現有的錢 + 投注的錢*3
  163.         blance = blance + bet*3;
  164.         // 把贏的錢做統計
  165.         money = money + bet*3;
  166.         cout<<"您贏了"<<bet*3<<"元"<<endl;
  167.     }else
  168.     {
  169.         // 把輸的錢做統計
  170.         money = money -bet;
  171.         cout<<"損失"<<bet<<"元"<<endl;
  172.     }
  173.    
  174.     // 局數+1  
  175.     n++;
  176.     system("pause");
  177.     goto re;     
  178.     end:
  179.    
  180.     if(money ==0 )
  181.     {
  182.        cout<<"沒輸沒贏! 全身而退!"<<endl;
  183.     }else if( money > 0)
  184.     {
  185.        cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
  186.     }else
  187.     {
  188.        cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
  189.     }
  190.     cout<<endl;
  191.     cout<<"謝謝光臨! 下次再來!"<<endl;
  192.     system("pause");  
  193.     return 0;   
  194. }
複製代碼

TOP

返回列表