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

TOP

返回列表