返回列表 發帖

賽馬程式 (八)

本帖最後由 tonyh 於 2013-11-30 14:56 編輯
  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<<"◆"<<endl;
  14.     cout<<"★"<<endl;
  15.     cout<<"▲"<<endl;
  16.     cout<<"●"<<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)◆ (2)★ (3)▲ (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!=70)&&(b!=70)&&(c!=70)&&(d!=70))
  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<<"◆"<<endl;
  75.              for(int i=1; i<=b; i++)
  76.                  cout<<" ";
  77.              cout<<"★"<<endl;
  78.              for(int i=1; i<=c; i++)
  79.                  cout<<" ";
  80.              cout<<"▲"<<endl;
  81.              for(int i=1; i<=d; i++)
  82.                  cout<<" ";
  83.              cout<<"●"<<endl;
  84.         system("cls");
  85.     }
  86.         if(a>b && a>c && a>d)
  87.         {
  88.              cout<<"◆ 勝出!";
  89.              winner=1;      
  90.         }else if(b>a && b>c && b>d)
  91.         {     
  92.              cout<<"★ 勝出!";
  93.              winner=2;      
  94.         }else if(c>a && c>b && c>d)
  95.         {
  96.              cout<<"▲ 勝出!";
  97.              winner=3;
  98.         }else
  99.         {
  100.              cout<<"● 勝出!";
  101.              winner=4;
  102.         }
  103.         cout<<endl<<"-------------------------------------------------------------------| 終點"<<endl;
  104.              for(int i=1; i<=a; i++)
  105.                  cout<<" ";
  106.              cout<<"◆"<<endl;
  107.              for(int i=1; i<=b; i++)
  108.                  cout<<" ";
  109.              cout<<"★"<<endl;
  110.              for(int i=1; i<=c; i++)
  111.                  cout<<" ";
  112.              cout<<"▲"<<endl;
  113.              for(int i=1; i<=d; i++)
  114.                  cout<<" ";
  115.              cout<<"●"<<endl;
  116.         if(option==winner)
  117.         {
  118.              cout<<endl<<"贏了 "<<bet*3<<"元!"<<endl;
  119.              balance+=bet*3;
  120.              money+=bet*3;
  121.         }else
  122.         {
  123.              cout<<endl<<"損失 "<<bet<<"元!"<<endl;
  124.              balance-=bet;
  125.              money-=bet;
  126.         }
  127.         cout<<endl;
  128.         n++;
  129.         system("pause");
  130.         goto re1;
  131.     end:
  132.         if(money==0)
  133.             cout<<endl<<"沒輸沒贏! 全身而退!"<<endl;
  134.         if(money>0)
  135.             cout<<endl<<"恭喜你! 這次總共贏了"<<money<<"元!"<<endl;
  136.         if(money<0)
  137.             cout<<endl<<"不好意思! 讓你損失了"<<-money<<"元!"<<endl;
  138.         cout<<endl<<"謝謝光臨! 下次再來!"<<endl<<endl;           
  139.     system("pause");
  140.     return 0;   
  141. }
複製代碼

返回列表