標題:
[作業] 賽馬程式 (六)
[打印本頁]
作者:
鄭繼威
時間:
2023-1-11 04:04
標題:
[作業] 賽馬程式 (六)
本帖最後由 鄭繼威 於 2023-1-11 21:12 編輯
1. 比對比賽結果與玩家下注,
判斷玩家贏了錢還是輸了錢
。
2. 對變數balance做加減,使
可用餘額會隨著玩家輸贏而增減
。
規則如下:
若最後勝出的選手與玩家下注相同,玩家贏得下注金3倍的錢。
反之,玩家損失下注金。
本帖隱藏的內容需要積分高於 1 才可瀏覽
作者:
李彣
時間:
2023-1-11 21:19
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int r=0, n=1, b, buy, option, bet, option2;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
cout<<p[i]<<endl;
}
cout<<"餘額"<<b<<"元"<<endl;
cout<<"(1)儲值(2)下注(3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"儲值:";
cin>>buy;
if(buy>=1)
{
b=b+buy;
goto re;
}
else if(buy<=0)
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
}
if(option==2)
{
cout<<"下注:";
cin>>bet;
if(bet<=b)
{
b=b-bet;
cout<<"(1)◆(2)★(3)▲(4)● 請選擇"<<endl;
cin>>option2;
cout<<"比賽即將開始....."<<endl;
_sleep(1500);
}
else if(bet>b)
{
cout<<"可用餘額不足,請先買入!"<<endl;
_sleep(1500);
goto re;
}
else if(bet<=0)
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
system("pause");
system("cls");
while(s[r]<=73)
{
r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
_sleep(50);
system("cls");
}
cout<<"比賽結束 "<<p[r]<<"贏"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
if(option2-1==r)
{
cout<<"賭贏"<<bet*3<<"元"<<endl;
b=b+bet*3;
}
else
{
cout<<"賭輸"<<bet<<"元"<<endl;
b-=bet;
}
n++;
system("pause");
goto re;
end:
return 0;
}
複製代碼
作者:
林劭杰
時間:
2023-1-12 08:02
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int r=0, n=1, b, buy, option, bet, option2;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
cout<<p[i]<<endl;
}
cout<<"餘額"<<b<<"元"<<endl;
cout<<"(1)儲值(2)下注(3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"儲值:";
cin>>buy;
if(buy>=1)
{
b=b+buy;
goto re;
}
else if(buy<=0)
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
}
if(option==2)
{
cout<<"下注:";
cin>>bet;
if(bet<=b)
{
b=b-bet;
cout<<"(1)◆(2)★(3)▲(4)● 請選擇"<<endl;
cin>>option2;
cout<<"比賽即將開始....."<<endl;
_sleep(1500);
}
else if(bet>b)
{
cout<<"可用餘額不足,請先買入!"<<endl;
_sleep(1500);
goto re;
}
else if(bet<=0)
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
system("pause");
system("cls");
while(s[r]<=73)
{
r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
_sleep(50);
system("cls");
}
cout<<"比賽結束 "<<p[r]<<"贏"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
if(option2-1==r)
{
cout<<"賭贏"<<bet*3<<"元"<<endl;
b=b+bet*3;
}
else
{
cout<<"賭輸"<<bet<<"元"<<endl;
b-=bet;
}
n++;
system("pause");
goto re;
end:
return 0;
}
複製代碼
作者:
黃裕恩
時間:
2023-1-18 18:46
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int r=0, n=1, b, buy, option, bet, option2;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
cout<<p[i]<<endl;
}
cout<<"餘額"<<b<<"元"<<endl;
cout<<"(1)儲值(2)下注(3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"儲值:";
cin>>buy;
if(buy>=1)
{
b=b+buy;
goto re;
}
else if(buy<=0)
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
}
if(option==2)
{
cout<<"下注:";
cin>>bet;
if(bet<=b)
{
cout<<"(1)◆(2)★(3)▲(4)● 請選擇"<<endl;
cin>>option2;
cout<<"比賽即將開始....."<<endl;
_sleep(1500);
}
else if(bet>b)
{
cout<<"可用餘額不足,請先買入!"<<endl;
_sleep(1500);
goto re;
}
else if(bet<=0)
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
system("pause");
system("cls");
while(s[r]<=73)
{
r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
_sleep(50);
system("cls");
}
cout<<"比賽結束 "<<p[r]<<"贏"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
if(option2-1==r)
{
cout<<"賭贏"<<bet*3<<"元"<<endl;
b=b+bet*3;
}
else
{
cout<<"賭輸"<<bet<<"元"<<endl;
b-=bet;
}
n++;
system("pause");
goto re;
end:
return 0;
}
複製代碼
作者:
連翊恩
時間:
2023-1-18 19:26
本帖最後由 鄭繼威 於 2023-1-18 19:45 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n=1, balance=0;
int option, buyin;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
cout<<p[i]<<endl;
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
balance+=buyin;
goto re;
}
int h;
int bet;
if(option==2){
cout<<"下注:";
cin>>bet;
if(bet<=0){
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
else if(bet>balance){
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇: ";
cin>>h;
cout<<"比賽即將開始"<<endl<<endl;
system("pause");
while(s[r]<=73)
{
r=rand()%4; //0~3
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
// _sleep(50);
system("cls");
}
}
cout<<"比賽結束! 由 "<<p[r]<<" 先馳得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
h--;
if(h == r){
balance += bet*3;
cout<<"贏得"<<bet*3<<"元";
_sleep(1500);
}
else{
balance -= bet;
cout<<"損失"<<bet<<"元";
_sleep(1500);
}
goto re;
system("pause");
n++;
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2