本帖最後由 陳品肇 於 2022-4-2 10:17 編輯
1. 比對比賽結果與玩家下注, 判斷玩家贏了錢還是輸了錢.
2. 對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.
規則如下:
若最後勝出的選手與玩家下注相同, 玩家贏得下注金3倍的錢.
反之, 玩家損失下注金.
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int n=1,money=0;
- re:
- int a=0, b=0, c=0, d=0, r, option, buyin, bet, horse,winner;
- system("cls");
- cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- cout<<endl;
- cout<<"可用餘額: "<<money<<"元"<<endl<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
- cin>>option;
- if(option==1) // 買入
- {
- cout<<"買入: ";
- cin>>buyin;
- money+=buyin; //money=money+buyin
- goto re;
- }else if(option ==2)
- {
- cout<<"請下注: ";
- cin>>bet;
- if(bet > money) //下注金額大於餘額
- {
- cout<<"您餘額不足,請重新下注!"<<endl;
- system("pause");
- goto re;
- }else if(bet>=0 && bet<= money)
- {
- cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
- cin>>horse;
- cout<<"比賽即將開始!"<<endl<<endl;
-
- }else
- {
- cout<<"您輸入錯誤!!請重新下注!"<<endl;
- system("pause");
- goto re;
- }
- }else //離開
- {
- goto end;
- }
- system("pause");
- system("cls");
- srand(time(NULL));
- while(a!=75 && b!=75 && c!=75 && d!=75)
- {
- r=rand()%4; //產生0~3之隨機亂數
- if(r==0)
- a++;
- else if(r==1)
- b++;
- else if(r==2)
- c++;
- else
- d++;
- cout<<"比賽進行中"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=1; i<=a; i++)
- cout<<" ";
- cout<<"◆"<<endl;
- for(int i=1; i<=b; i++)
- cout<<" ";
- cout<<"★"<<endl;
- for(int i=1; i<=c; i++)
- cout<<" ";
- cout<<"▲"<<endl;
- for(int i=1; i<=d; i++)
- cout<<" ";
- cout<<"●"<<endl;
- system("cls");
- }
- cout<<"比賽結束! 由 ";
- if(a==75)
- {
- cout<<"◆";
- winner = 1;
- }
- else if(b==75)
- {
- cout<<"★";
- winner = 2;
- }
- else if(c==75)
- {
- cout<<"▲";
- winner = 3;
- }
- else
- {
- cout<<"●";
- winner = 4;
- }
- cout<<" 先馳得點!"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=1; i<=a; i++)
- cout<<" ";
- cout<<"◆"<<endl;
- for(int i=1; i<=b; i++)
- cout<<" ";
- cout<<"★"<<endl;
- for(int i=1; i<=c; i++)
- cout<<" ";
- cout<<"▲"<<endl;
- for(int i=1; i<=d; i++)
- cout<<" ";
- cout<<"●"<<endl;
-
-
- if(horse ==winner) //選的馬跟贏的馬是否同一隻
- {
- money += bet*3; //贏的話給3倍
- cout<<"贏了"<<bet*3<<"元!"<<endl;
- }else
- {
- money -= bet; // money = money - bet;
- cout<<"損失"<<bet<<"元!"<<endl;
- }
-
- system("pause");
- n++;
- goto re;
- end:
- system("pause");
- return 0;
- }
複製代碼 |