返回列表 發帖
本帖最後由 吳秉翰 於 2018-5-26 14:00 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.   int times=1;
  8.   int point=0;
  9.   int select=0;
  10.   int buy=0;
  11.   int bet=0;
  12.   int my_select=0;
  13.   int win=0;
  14.   bool isStart=true;
  15.   while(true)
  16.   {
  17.     int h1=0, h2=0, h3=0, h4=0, random=0;
  18.     srand(time(NULL));
  19.     cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  20.     cout<< "可用帳戶餘額:"<<point<<endl;
  21.     while(isStart)
  22.     {
  23.       cout<< "(1)儲值(2)下注(3)離開 請選擇:";
  24.       cin >> select;
  25.       switch(select)
  26.       {
  27.         case 1:
  28.         cout << "買入:";
  29.         cin >> buy;
  30.         point += (buy<=0) ? point : buy;
  31.         cout<< "可用帳戶餘額:" <<  point << endl;
  32.         break;
  33.         case 2:
  34.         cout << "下注:";
  35.         cin >> bet;
  36.         cout<<"請下注:(1)◆(2)★(3)▲(4)●"<<endl;
  37.         cin>>my_select;
  38.         if(point<=0 || point<bet)
  39.         {
  40.           cout<<"餘額不足"<<endl;
  41.           break;
  42.         }
  43.         string error = (bet>point || bet<=0) ? "輸入錯誤":"";
  44.         if(error == "error")
  45.         {
  46.           break;
  47.         }
  48.         else
  49.         {
  50.           isStart = false;
  51.         }
  52.         point-=bet;
  53.         break;
  54.       }
  55.     }
  56.       system("pause");
  57.       system("cls");
  58.       while(h1!=75 && h2!=75 && h3!=75 && h4!=75)
  59.       {
  60.         random=rand()%4;
  61.         if(random==0)
  62.         {
  63.            h1++;
  64.         }
  65.         else if(random==1)
  66.         {
  67.            h2++;
  68.         }
  69.         else if(random==2)
  70.         {
  71.            h3++;
  72.         }
  73.         else if(random==3)
  74.         {
  75.            h4++;
  76.         }
  77.         cout<<"比賽進行中"<<endl;
  78.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  79.         for(int i=1; i<=h1; i++)
  80.         {
  81.           cout<<" ";
  82.         }
  83.         cout<<"◆"<<endl;
  84.         for(int i=1; i<=h2; i++)
  85.         {
  86.           cout<<" ";
  87.         }
  88.         cout<<"★"<<endl;
  89.         for(int i=1; i<=h3; i++)
  90.         {
  91.           cout<<" ";
  92.         }
  93.         cout<<"▲"<<endl;
  94.         for(int i=1; i<=h4; i++)
  95.         {
  96.           cout<<" ";
  97.         }
  98.         cout<<"●"<<endl;
  99.         system("cls");
  100.     }
  101.     times++;
  102.     system("cls");
  103.     if(h1==75)
  104.     {
  105.       cout<<"比賽結束,由◆先馳得點"<<endl;
  106.       win=1;
  107.     }
  108.     else if(h2==75)
  109.     {
  110.       cout<<"比賽結束,由★先馳得點"<<endl;
  111.       win=2;
  112.     }
  113.     else if(h3==75)
  114.     {
  115.       cout<<"比賽結束,由▲先馳得點"<<endl;
  116.       win=3;
  117.     }
  118.     else if(h4==75)
  119.     {
  120.       cout<<"比賽結束,由●先馳得點"<<endl;
  121.       win=4;
  122.     }
  123.     if(my_select==win)
  124.     {
  125.     point+=bet*3;
  126.     }
  127.     isStart=true
  128.   }
  129.     system("pause");
  130.     return 0;  
  131. }
複製代碼

TOP

返回列表