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

返回列表