返回列表 發帖
  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

  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

返回列表