返回列表 發帖

[作業] 賽馬程式 (七)

本帖最後由 葉桔良 於 2022-9-17 15:53 編輯

完成選項 (3)離開 的相對應程式碼
在離開時顯示戰果,譬如:
"沒輸沒贏!全身而退!"
"恭喜你!這次總共贏了100元!"
"不好意思!讓你損失了200元!"

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n=1, balance=0;
  8.     int option, buyin, bet, player;
  9.     re:
  10.     system("cls");
  11.     srand(time(NULL));
  12.     int s[]={0,0,0,0};
  13.     string p[]={"◆","★","▲","●"};
  14.     int r=0;
  15.     cout<<"「好事成雙」賽馬場  第 "<<n<<" 局"<<endl;
  16.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  17.     for(int i=0; i<4; i++)
  18.         cout<<p[i]<<endl;
  19.     cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  20.     cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
  21.     cin>>option;
  22.     if(option==1)
  23.     {
  24.         cout<<"買入: ";
  25.         cin>>buyin;
  26.         if(buyin<=0)
  27.         {
  28.              cout<<"輸入錯誤!";
  29.              _sleep(1500);
  30.              goto re;     
  31.         }
  32.         balance+=buyin;
  33.         goto re;         
  34.     }
  35.     else if(option==2)
  36.     {
  37.         cout<<"下注: ";
  38.         cin>>bet;
  39.         if(bet<=0)
  40.         {
  41.              cout<<"輸入錯誤!";
  42.              _sleep(1500);
  43.              goto re;     
  44.         }
  45.         if(bet>balance)
  46.         {
  47.              cout<<"可用餘額不足,請先買入!";
  48.              _sleep(1500);
  49.              goto re;     
  50.         }
  51.         cout<<endl<<"(1)◆ (2)★ (3)▲ (4)● 請選擇: ";
  52.         cin>>player;
  53.         cout<<"比賽即將開始..."<<endl<<endl;         
  54.     }
  55.     else if(option==3)
  56.     {
  57.         goto end;         
  58.     }
  59.     else
  60.     {
  61.         cout<<"輸入錯誤!";
  62.         _sleep(1500);
  63.         goto re;
  64.     }
  65.     system("pause");
  66.     system("cls");
  67.     while(s[r]<=73)
  68.     {
  69.         r=rand()%4;   //0~3
  70.         s[r]++;
  71.         cout<<"比賽進行中"<<endl;
  72.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  73.         for(int i=0; i<4; i++)
  74.         {
  75.             for(int j=0; j<s[i]; j++)
  76.                 cout<<" ";
  77.             cout<<p[i]<<endl;
  78.         }
  79.         _sleep(25);
  80.         system("cls");
  81.     }
  82.     cout<<"比賽結束!  由 "<<p[r]<<" 先馳得點!"<<endl;
  83.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  84.     for(int i=0; i<4; i++)
  85.     {
  86.         for(int j=0; j<s[i]; j++)
  87.             cout<<" ";
  88.         cout<<p[i]<<endl;
  89.     }
  90.     if(player==r+1)
  91.     {
  92.         cout<<"贏了 "<<bet*3<<" 元!"<<endl;
  93.         balance+=bet*3;                  
  94.     }else
  95.     {
  96.         cout<<"損失 "<<bet<<" 元!"<<endl;
  97.         balance-=bet;  
  98.     }
  99.     system("pause");
  100.     n++;
  101.     goto re;
  102.     end:
  103.     cout<<endl<<"慢走!"<<endl;
  104.     _sleep(1500);
  105.     return 0;
  106. }
複製代碼

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表