返回列表 發帖

[作業] 賽馬程式 (六)

本帖最後由 鄭繼威 於 2023-1-11 21:12 編輯

1. 比對比賽結果與玩家下注,判斷玩家贏了錢還是輸了錢
2. 對變數balance做加減,使可用餘額會隨著玩家輸贏而增減

規則如下:
若最後勝出的選手與玩家下注相同,玩家贏得下注金3倍的錢。
反之,玩家損失下注金。





本帖隱藏的內容需要積分高於 1 才可瀏覽

本帖最後由 鄭繼威 於 2023-1-18 19:45 編輯
  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;
  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.         balance+=buyin;
  27.         goto re;         
  28.     }
  29.     int h;
  30.     int bet;
  31.     if(option==2){
  32.         cout<<"下注:";
  33.         cin>>bet;
  34.         if(bet<=0){
  35.             cout<<"輸入錯誤!";
  36.             _sleep(1500);
  37.             goto re;
  38.         }
  39.         else if(bet>balance){
  40.             cout<<"可用餘額不足,請先買入!";
  41.             _sleep(1500);
  42.             goto re;
  43.         }
  44.         cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇: ";
  45.         cin>>h;
  46.         cout<<"比賽即將開始"<<endl<<endl;
  47.         system("pause");
  48.         
  49.         while(s[r]<=73)
  50.         {
  51.             r=rand()%4;   //0~3
  52.             s[r]++;
  53.             cout<<"比賽進行中"<<endl;
  54.             cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  55.             for(int i=0; i<4; i++)
  56.             {
  57.             for(int j=0; j<s[i]; j++)
  58.                 cout<<" ";
  59.             cout<<p[i]<<endl;
  60.             }
  61.           //  _sleep(50);
  62.             system("cls");
  63.         }
  64.     }
  65.     cout<<"比賽結束!  由 "<<p[r]<<" 先馳得點!"<<endl;
  66.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  67.     for(int i=0; i<4; i++)
  68.     {
  69.         for(int j=0; j<s[i]; j++)
  70.             cout<<" ";
  71.         cout<<p[i]<<endl;
  72.     }
  73.     h--;
  74.     if(h == r){
  75.          balance += bet*3;
  76.          cout<<"贏得"<<bet*3<<"元";
  77.          _sleep(1500);
  78.     }
  79.     else{
  80.         balance -= bet;
  81.         cout<<"損失"<<bet<<"元";
  82.         _sleep(1500);
  83.     }
  84.     goto re;
  85.     system("pause");
  86.     n++;
  87.     goto re;
  88.     return 0;
  89. }
複製代碼

TOP

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

TOP

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

TOP

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

TOP

返回列表