返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int balance=0, n=1, money=0;
  7.     int option, buyin, bet, winner;
  8.     re1:
  9.     int a=0, b=0, c=0, d=0, r;
  10.     system("cls");
  11.     cout<<"「好事雙成」賽馬場 第"<<n<<"局"<<endl;
  12.     cout<<"---------------------------------------------------------|終點"<<endl;
  13.     cout<<"◥1◣"<<endl;
  14.     cout<<"◥2◣"<<endl;
  15.     cout<<"◥3◣"<<endl;
  16.     cout<<"◥4◣"<<endl;
  17.     re2:
  18.     cout<<endl<<"可用餘額:"<<balance<<"元"<<endl<<endl;
  19.     cout<<"(1)買入(2)下注(3)離開 請選擇: ";
  20.     cin>>option;
  21.     if(option==1)
  22.     {
  23.         cout<<"買入: ";
  24.         cin>>buyin;
  25.         balance+=buyin;
  26.         goto re1;
  27.     }else if(option==2)
  28.     {
  29.         if(balance==0)
  30.         {
  31.              cout<<"可用餘額不足!請先買入!" <<endl<<endl;
  32.              system("pause");
  33.              goto re1;
  34.         }
  35.         cout<<"下注: ";
  36.         cin>>bet;
  37.         if(bet>balance)
  38.         {
  39.              cout<<"可用餘額不足!請先買入!" <<endl<<endl;
  40.              system("pause");
  41.              goto re1;         
  42.         }else
  43.         {
  44.              cout<<endl<<"(1)◥1◣(2)◥2◣(3)◥3◣(4)◥4◣請選擇: ";
  45.              cin>>option;
  46.              cout<<"比賽即將開始!"<<endl<<endl;
  47.              system("pause");
  48.         }
  49.     }else if(option==3)
  50.     {
  51.         goto end;  
  52.     }else
  53.     {
  54.         cout<<"輸入錯誤!"<<endl<<endl;
  55.         system("pause");
  56.         goto re1;
  57.     }
  58.     srand(time(NULL));
  59.     while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
  60.     {
  61.              r=rand()%4;
  62.              if(r==0)
  63.                a++;     
  64.              else if(r==1)
  65.                b++;   
  66.              else if(r==2)
  67.                c++;   
  68.              else
  69.                d++;   
  70.              cout<<"比賽進行中...";
  71.              cout<<endl<<"---------------------------------------------------------|終點"<<endl;
  72.                for(int i=1;i<=a;i++)
  73.                  cout<<" ";
  74.                cout<<"◥1◣"<<endl;     
  75.                for(int i=1;i<=b;i++)
  76.                  cout<<" ";
  77.                cout<<"◥2◣"<<endl;
  78.                for(int i=1;i<=c;i++)
  79.                  cout<<" ";
  80.                cout<<"◥3◣"<<endl;     
  81.                for(int i=1;i<=d;i++)
  82.                  cout<<" ";
  83.                cout<<"◥4◣"<<endl;
  84.                system("cls");                           
  85.          }
  86.                if(a>b&&a>c&&a>d)
  87.                {
  88.                     cout<<"◥1◣勝出!";
  89.                     winner=1;            
  90.                }else if(b>a&&b>c&&b>d)
  91.                {
  92.                     cout<<"◥2◣勝出!";
  93.                     winner=2;            
  94.                }else if(c>a&&c>b&&c>d)
  95.                {
  96.                     cout<<"◥3◣勝出!";
  97.                     winner=3;            
  98.                }else
  99.                {
  100.                     cout<<"◥4◣勝出!";
  101.                     winner=4;            
  102.                }   
  103.                cout<<"比賽結束!"<<endl;
  104.                cout<<"---------------------------------------------------------|終點"<<endl;
  105.                for(int i=1;i<=a;i++)
  106.                  cout<<" ";
  107.                cout<<"◥1◣"<<endl;     
  108.                for(int i=1;i<=b;i++)
  109.                  cout<<" ";
  110.                cout<<"◥2◣"<<endl;
  111.                for(int i=1;i<=c;i++)
  112.                  cout<<" ";
  113.                cout<<"◥3◣"<<endl;     
  114.                for(int i=1;i<=d;i++)
  115.                  cout<<" ";
  116.                cout<<"◥4◣"<<endl;
  117.      if(option==3)         
  118.      {
  119.           cout<<endl<<"贏了"<<bet*3<<"元!"<<endl;
  120.           balance+=bet*3;
  121.           money+=bet*3;                                    
  122.      }else
  123.      {
  124.           cout<<endl<<"損失"<<bet<<"元!"<<endl;
  125.           balance-=bet;
  126.           money-=bet;                           
  127.      }
  128.      goto re1;
  129.      end:                    
  130.     system("pause");
  131.     return 0;  
  132. }
複製代碼

TOP

返回列表