返回列表 發帖
  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<<endl;
  17.     cout<<"可用餘額: "<<money<<"元"<<endl<<endl;
  18.     cout<<"(1)買入  (2)下注  (3)離開  請選擇: ";
  19.     cin>>option;
  20.     if(option==1)
  21.     {
  22.         cout<<"買入: ";
  23.         cin>>buyin;
  24.         money+=buyin;   
  25.         goto re;
  26.     }else if(option ==2)
  27.     {
  28.         cout<<"請下注: ";
  29.         cin>>bet;
  30.         if(bet > money)
  31.         {
  32.             cout<<"您餘額不足,請重新下注!"<<endl;
  33.             system("pause");
  34.             goto re;
  35.         }else if(bet>=0 && bet<= money)
  36.         {
  37.             cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
  38.             cin>>horse;
  39.             cout<<"比賽即將開始!"<<endl<<endl;
  40.       
  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!=75 && b!=75 && c!=75 && d!=75)
  55.     {
  56.         r=rand()%4;   
  57.         if(r==0)
  58.             a++;
  59.         else if(r==1)
  60.             b++;
  61.         else if(r==2)
  62.             c++;
  63.         else
  64.             d++;
  65.         cout<<"比賽進行中"<<endl;
  66.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  67.         for(int i=1; i<=a; i++)
  68.             cout<<" ";
  69.         cout<<"◆"<<endl;
  70.         for(int i=1; i<=b; i++)
  71.             cout<<" ";
  72.         cout<<"★"<<endl;
  73.         for(int i=1; i<=c; i++)
  74.             cout<<" ";
  75.         cout<<"▲"<<endl;
  76.         for(int i=1; i<=d; i++)
  77.             cout<<" ";
  78.         cout<<"●"<<endl;   
  79.         system("cls");      
  80.     }
  81.     cout<<"比賽結束! 由 ";
  82.     if(a==75)
  83.     {
  84.         cout<<"◆";
  85.         winner = 1;
  86.     }
  87.     else if(b==75)
  88.     {
  89.         cout<<"★";
  90.         winner = 2;
  91.     }
  92.     else if(c==75)
  93.     {
  94.         cout<<"▲";
  95.         winner = 3;
  96.     }
  97.     else
  98.     {
  99.         cout<<"●";
  100.         winner = 4;
  101.     }
  102.     cout<<" 先馳得點!"<<endl;
  103.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  104.     for(int i=1; i<=a; i++)
  105.         cout<<" ";
  106.     cout<<"◆"<<endl;
  107.     for(int i=1; i<=b; i++)
  108.         cout<<" ";
  109.     cout<<"★"<<endl;
  110.     for(int i=1; i<=c; i++)
  111.         cout<<" ";
  112.     cout<<"▲"<<endl;
  113.     for(int i=1; i<=d; i++)
  114.         cout<<" ";
  115.     cout<<"●"<<endl;
  116.    
  117.    
  118.     if(horse ==winner)  
  119.     {
  120.            money += bet*3;
  121.            cout<<"贏了"<<bet*3<<"元!"<<endl;
  122.     }else
  123.     {
  124.            money -= bet;
  125.            cout<<"損失"<<bet<<"元!"<<endl;
  126.     }
  127.    
  128.     system("pause");
  129.     n++;
  130.     goto re;
  131.     end:
  132.     system("pause");
  133.     return 0;   
  134. }
複製代碼

TOP

返回列表