標題:
賽馬程式 (六)
[打印本頁]
作者:
tonyh
時間:
2017-5-20 13:47
標題:
賽馬程式 (六)
本帖最後由 tonyh 於 2020-2-14 14:26 編輯
1. 比對比賽結果與玩家下注, 判斷玩家贏了錢還是輸了錢.
2. 對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.
規則如下:
若最後勝出的選手與玩家下注相同, 玩家贏得下注金3倍的錢.
反之, 玩家損失下注金.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1, winner, balance=0, option, buyin, bet, player;
srand(time(NULL));
re:
system("cls");
int s[]={0,0,0,0};
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"- - - - - - - - - - - 終點"<<endl;
cout<<"1"<<endl;
cout<<"2"<<endl;
cout<<"3"<<endl;
cout<<"4"<<endl;
cout<<endl<<"可用餘額: "<<balance<<" 元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
if(buyin<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance+=buyin;
goto re;
}
else if(option==2)
{
cout<<"下注: ";
cin>>bet;
if(bet<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(bet>balance)
{
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<endl<<"1號 2號 3號 4號 請選擇: ";
cin>>player;
cout<<"比賽即將開始..."<<endl<<endl;
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4; //0~3
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"- - - - - - - - - - - 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
if(s[r]==44)
{
winner=r+1;
break;
}
_sleep(60);
}
system("cls");
cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
cout<<"- - - - - - - - - - - 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
n++;
if(winner==player)
{
cout<<"贏了 "<<bet*3<<" 元!"<<endl;
balance+=bet*3;
}else
{
cout<<"損失 "<<bet<<" 元!"<<endl;
balance-=bet;
}
system("pause");
goto re;
end:
cout<<endl<<"慢走!"<<endl;
_sleep(1500);
return 0;
}
複製代碼
作者:
許紘誌
時間:
2017-5-20 14:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int x=1,balance=0,option,buyin,bet,player,wallet=0;
re:
system("cls");
string n[]={"1","2","3","4"};
int s[]={0,0,0,0};
int r;
cout<<"「好事成雙」賽馬場 第"<<x<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
cout<<n[i]<<endl;
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
if(buyin<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance+=buyin;
goto re;
}
else if(option==2)
{
cout<<"下注: ";
cin>>bet;
if(bet<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(bet>balance)
{
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<endl<<"1號 2號 3號 4號 請選擇: ";
cin>>player;
if(player>=5 || player<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
cout<<"比賽即將開始..."<<endl<<endl;
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
system("pause");
while(true)
{
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
r=rand()%4;
s[r]++;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<n[i]<<endl;
}
_sleep(10);
system("cls");
if(s[r]==76)
break;
}
cout<<"比賽結果! 由 "<<n[r]<<" 先馳得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<n[i]<<endl;
}
if(player-1==r)
{
cout<<"獲得"<<bet*3<<"元"<<endl;
balance=bet*3+balance;
wallet+=bet+3;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
balance=balance-bet;
wallet-=bet;
}
system("pause");
x++;
goto re;
end:
if(wallet==0)
cout<<"沒輸沒贏! 全身而退"<<endl<<endl;
else if(wallet>0)
cout<<"恭喜你! 這次總共贏了"<<wallet<<"元"<<endl<<endl;
else
cout<<"不好意思! 讓你損失了"<<-wallet<<"元"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2017-5-20 14:27
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a=1, win, x=0, y, z, b, c;
srand(time(NULL));
re:
system("cls");
int s[]={0,0,0,0};
cout<<"「好事成雙」賽馬場! 第 "<<a<<" 局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"*_* 1"<<endl;
cout<<"$_$ 2"<<endl;
cout<<"+_+ 3"<<endl;
cout<<"#_# 4"<<endl;
cout<<endl<<"可用餘額: "<<x<<" 元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>y;
if(y==1)
{
cout<<"買入: ";
cin>>z;
if(z<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
x+=z;
goto re;
}else if(y==2)
{
cout<<"下注: ";
cin>>b;
if(b<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(b>x)
{
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<"(1)*_* 1 (2)$_$ 2 (3)+_+ 3 (4)#_# 4 請選擇: ";
cin>>c;
cout<<"比賽即將開始..."<<endl<<endl;
}else if(y==3)
{
goto end;
}else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"*_* 1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"$_$ 2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"+_+ 3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"#_# 4"<<endl;
if(s[r]==73)
{
win=r+1;
break;
}
_sleep(50);
}
system("cls");
cout<<"比賽結束! 由 "<<win<<" 先持得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"*_* 1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"$_$ 2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"+_+ 3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"#_# 4"<<endl;
if(c==win)
{
cout<<"贏得 "<<b*3<<"元"<<endl;
x+=b*3;
}else
{
cout<<"損失 "<<b<<" 元"<<endl;
x-=b;
}
cout<<endl<<"可用餘額: "<<x<<" 元"<<endl<<endl;
system("pause");
a++;
goto re;
end:
cout<<endl<<"慢走!"<<endl;
_sleep(1500);
return 0;
}
複製代碼
作者:
黃宥鈞
時間:
2017-5-20 14:36
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1, winner, balance=0, option, buyin, bet, player;
srand(time(NULL));
re:
system("cls");
int s[]={0,0,0,0};
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"- - - - - - - - - - - 終點"<<endl;
cout<<"1"<<endl;
cout<<"2"<<endl;
cout<<"3"<<endl;
cout<<"4"<<endl;
cout<<endl<<"可用餘額: "<<balance<<" 元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
if(buyin<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance+=buyin;
goto re;
}
else if(option==2)
{
cout<<"下注: ";
cin>>bet;
if(bet<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(bet>balance)
{
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<endl<<"1號 2號 3號 4號 請選擇: ";
cin>>player;
cout<<"比賽即將開始..."<<endl<<endl;
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4; //0~3
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"- - - - - - - - - - - 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
if(s[r]==45)
{
winner=r+1;
break;
}
_sleep(60);
}
system("cls");
cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
cout<<"- - - - - - - - - - - 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
n++;
if(winner!=player)
{
cout<<"損失"<<bet<<"元"<<endl;
balance-=bet;
}
if(winner==player)
{
cout<<"贏得"<<bet*3<<"元";
balance+=bet*3;
}
system("pause");
goto re;
end:
cout<<endl<<"慢走!"<<endl;
_sleep(1500);
return 0;
}
複製代碼
作者:
譚暐霖
時間:
2017-5-20 14:37
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a=1, win, x=0, y, z, b, c;
srand(time(NULL));
re:
system("cls");
int s[]={0,0,0,0};
cout<<"「好事成雙」賽馬場! 第 "<<a<<" 局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"1"<<endl;
cout<<"2"<<endl;
cout<<"3"<<endl;
cout<<"4"<<endl;
cout<<endl<<"可用餘額: "<<x<<" 元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>y;
if(y==1)
{
cout<<"買入: ";
cin>>z;
if(z<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
x+=z;
goto re;
}else if(y==2)
{
cout<<"下注: ";
cin>>b;
if(b<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(b>x)
{
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<"(1)1 (2)2 (3)3 (4)4 請選擇: ";
cin>>c;
cout<<"比賽即將開始..."<<endl<<endl;
}else if(y==3)
{
goto end;
}else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
if(s[r]==73)
{
win=r+1;
break;
}
_sleep(50);
}
system("cls");
cout<<"比賽結束! 由 "<<win<<" 先持得點!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
if(c==win)
{
cout<<"贏得 "<<b*3<<"元"<<endl;
x+=b*3;
}else
{
cout<<"損失 "<<b<<" 元"<<endl;
x-=b;
}
cout<<endl<<"可用餘額: "<<x<<" 元"<<endl<<endl;
system("pause");
a++;
goto re;
end:
cout<<endl<<"慢走!"<<endl;
_sleep(1500);
return 0;
}
複製代碼
作者:
蕭澧邦
時間:
2017-5-20 14:39
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int win;
int num=1;
int balance=0;
int buyin;
int option;
int bet;
int players;
re:
system("cls");
int s[]={0,0,0,0};
string horse[]={"◆", "★", "▲", "●"};
cout<<"「好事成雙」賽馬場 第"<<num<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"可用餘額"<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
if(buyin<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance+=buyin;
goto re;
}
if(option==2)
{
cout<<"下注: ";
cin>>bet;
if(bet<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(bet>balance)
{
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<endl<<"(1)◆ (2)★ (3)▲ (4)● 請選擇: ";
cin>>players;
if(players<=0 || players>4)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance-=bet;
goto start;
}
else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
start:
cout<<"比賽即將開始..."<<endl<<endl;
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
win=r;
if(s[r]==73)
break;
_sleep(50);
}
system("cls");
cout<<"比賽結束! 由 "<<horse[win]<<" 勝出!"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
if(win==players)
{
balance+=bet*3;
}
else
{
cout<<"損失"<<bet<<"元!"<<endl;
}
system("pause");
num++;
goto re;
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2017-5-20 15:33
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1, winner, balance=0, option, buyin, bet, player;
srand(time(NULL));
re:
system("cls");
int s[]={0,0,0,0};
cout<<"「好棒棒」狗寶寶賽跑第 "<<n<<" 局"<<endl;
cout<<"----------------------------------------------終點"<<endl;
cout<<"狗寶寶賽 1"<<endl;
cout<<"狗寶寶賽 2"<<endl;
cout<<"狗寶寶賽 3"<<endl;
cout<<"狗寶寶賽 4"<<endl;
cout<<endl<<"可用餘額: "<<balance<<" 元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
if(buyin<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance+=buyin;
goto re;
}
else if(option==2)
{
cout<<"下注: ";
cin>>bet;
if(bet<=0)
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(bet>balance)
{
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
cout<<endl<<"狗寶寶賽1號 狗寶寶賽2號 狗寶寶賽3號 狗寶寶賽4號 請選擇: ";
cin>>player;
cout<<"比賽即將開始..."<<endl<<endl;
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"----------------------------------------------終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
if(s[r]==44)
{
winner=r+1;
break;
}
_sleep(60);
}
system("cls");
cout<<"比賽結束! 由 "<<winner<<" 號狗寶寶先馳得點!"<<endl;
cout<<"----------------------------------------------終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"1"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"2"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"3"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"4"<<endl;
n++;
if(winner==player)
{
cout<<"贏了 "<<bet*3<<" 元!恭喜你喲~~"<<endl;
balance+=bet*3;
}else
{
cout<<"損失 "<<bet<<" 元!"<<endl;
balance-=bet;
}
system("pause");
goto re;
end:
cout<<endl<<"掰掰!"<<endl;
_sleep(1500);
return 0;
}
[/code]
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2