返回列表 發帖
本帖最後由 許逸群 於 2013-11-9 14:19 編輯
  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.         cout<<"輸入錯誤!"<<endl<<endl;
  52.         system("pause");
  53.         goto re1;
  54.     }
  55.     srand(time(NULL));
  56.     while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
  57.     {
  58.              r=rand()%4;
  59.              if(r==0)
  60.                a++;     
  61.              else if(r==1)
  62.                b++;   
  63.              else if(r==2)
  64.                c++;   
  65.              else
  66.                d++;   
  67.              cout<<"比賽進行中...";
  68.              cout<<endl<<"---------------------------------------------------------|終點"<<endl;
  69.                for(int i=1;i<=a;i++)
  70.                  cout<<" ";
  71.                cout<<"◥1◣"<<endl;     
  72.                for(int i=1;i<=b;i++)
  73.                  cout<<" ";
  74.                cout<<"◥2◣"<<endl;
  75.                for(int i=1;i<=c;i++)
  76.                  cout<<" ";
  77.                cout<<"◥3◣"<<endl;     
  78.                for(int i=1;i<=d;i++)
  79.                  cout<<" ";
  80.                cout<<"◥4◣"<<endl;
  81.                system("cls");                           
  82.          }
  83.                if(a>b&&a>c&&a>d)
  84.                  winner=1;
  85.                else if(b>a&&b>c&&b>d)
  86.                  winner=2;
  87.                else if(c>a&&c>b&&c>d)
  88.                  winner=3;
  89.                else
  90.                  winner=4;
  91.                  
  92.                cout<<"比賽結束!"<<endl;
  93.                cout<<"由"<<winner<<"號選手拿到勝利----------------------------------------|終點"<<endl;
  94.                for(int i=1;i<=a;i++)
  95.                  cout<<" ";
  96.                cout<<"◥1◣"<<endl;     
  97.                for(int i=1;i<=b;i++)
  98.                  cout<<" ";
  99.                cout<<"◥2◣"<<endl;
  100.                for(int i=1;i<=c;i++)
  101.                  cout<<" ";
  102.                cout<<"◥3◣"<<endl;     
  103.                for(int i=1;i<=d;i++)
  104.                  cout<<" ";
  105.                cout<<"◥4◣"<<endl;                                       
  106.     system("pause");
  107.     return 0;  
  108. }
複製代碼

TOP

返回列表