返回列表 發帖
本帖最後由 吳孟修 於 2019-4-27 15:17 編輯
  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,horse,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<<"\n可用金額:"<<money<<"元\n"<<endl;
  17.     cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
  18.     cin>>option;
  19.     if(option==1)
  20.     {
  21.         cout<<"請買入:";
  22.         cin>>buyin;
  23.         if(buyin<0)
  24.         {
  25.             cout<<"您輸入的金額有誤,請重新買入!"<<endl;
  26.         }
  27.         money+=buyin;
  28.         goto re;            
  29.     }
  30.     else if(option==2)
  31.     {
  32.         cout<<"請下注:";
  33.         cin>>bet;
  34.         if(bet>money)
  35.         {
  36.             cout<<"您的金額不足,請重新下注!"<<endl;            
  37.             system("pause");
  38.             goto re;
  39.         }
  40.         else if(bet>=0 && bet<=money)
  41.         {
  42.             cout<<"(1)◆ (2)★ (3)▲ (4)● 請選擇:";
  43.             cin>>horse;
  44.             cout<<"比賽即將開始!\n\n";     
  45.         }
  46.         else
  47.         {
  48.             cout<<"您輸入的金額有誤,請重新下注!"<<endl;
  49.             system("pause");
  50.             goto re;   
  51.         }         
  52.     }
  53.     else if(option==3)
  54.     {
  55.         goto end;     
  56.     }
  57.     else
  58.     {
  59.         cout<<"您輸入錯誤,請重新選擇!"<<endl;
  60.         system("pause");
  61.         goto re;   
  62.     }
  63.     system("pause");
  64.     system("cls");
  65.     srand(time(NULL));
  66.     while(a!=70 && b!=70 && c!=70 && d!=70)
  67.     {
  68.         cout<<"比賽進行中"<<endl;
  69.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  70.         r=rand()%4+1;
  71.         if(r==1)
  72.         {
  73.             a++;        
  74.         }
  75.         if(r==2)
  76.         {
  77.             b++;        
  78.         }
  79.         if(r==3)
  80.         {
  81.             c++;        
  82.         }
  83.         if(r==4)
  84.         {
  85.             d++;        
  86.         }
  87.         for(int i=0;i<=a;i++)
  88.         {
  89.             cout<<" ";        
  90.         }
  91.         cout<<"◆"<<endl;
  92.         for(int i=0;i<=b;i++)
  93.         {
  94.             cout<<" ";        
  95.         }
  96.         cout<<"★"<<endl;
  97.         for(int i=0;i<=c;i++)
  98.         {
  99.             cout<<" ";        
  100.         }
  101.         cout<<"▲"<<endl;
  102.         for(int i=0;i<=d;i++)
  103.         {
  104.             cout<<" ";        
  105.         }
  106.         cout<<"●"<<endl;
  107.         system("cls");            
  108.     }
  109.     cout<<"比賽結束!由";
  110.     if(a==70)
  111.     {
  112.         cout<<"◆";
  113.         winner=1;         
  114.     }
  115.     if(b==70)
  116.     {
  117.         cout<<"★";
  118.         winner=2;        
  119.     }
  120.     if(c==70)
  121.     {
  122.         cout<<"▲";
  123.         winner=3;      
  124.     }
  125.     if(d==70)
  126.     {
  127.         cout<<"●";
  128.         winner=4;         
  129.     }
  130.     cout<<"先馳得點!"<<endl;
  131.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  132.     for(int i=0;i<=a;i++)
  133.     {
  134.         cout<<" ";        
  135.     }
  136.     cout<<"◆"<<endl;
  137.     for(int i=0;i<=b;i++)
  138.     {
  139.         cout<<" ";        
  140.     }
  141.     cout<<"★"<<endl;
  142.     for(int i=0;i<=c;i++)
  143.     {
  144.         cout<<" ";        
  145.     }
  146.     cout<<"▲"<<endl;
  147.     for(int i=0;i<=d;i++)
  148.     {
  149.         cout<<" ";        
  150.     }
  151.     cout<<"●"<<endl;
  152.     if(horse==winner)
  153.     {
  154.         money+=bet*3;
  155.         cout<<"贏了"<<bet*3<<"元!"<<endl;                 
  156.     }
  157.     else
  158.     {
  159.         money-=bet;
  160.         cout<<"損失"<<bet<<"元!"<<endl;
  161.     }
  162.     system("pause");
  163.     system("cls");
  164.     n++;
  165.     goto re;
  166.     end:
  167.     system("pause");
  168.     return 0;   
  169. }
複製代碼

TOP

返回列表