標題:
賽馬程式(六)
[打印本頁]
作者:
陳品肇
時間:
2019-4-27 14:46
標題:
賽馬程式(六)
本帖最後由 陳品肇 於 2022-4-2 10:17 編輯
1. 比對比賽結果與玩家下注, 判斷玩家贏了錢還是輸了錢.
2. 對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.
規則如下:
若最後勝出的選手與玩家下注相同, 玩家贏得下注金3倍的錢.
反之, 玩家損失下注金.
[attach]6339[/attach]
[attach]6338[/attach]
[attach]6337[/attach]
#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;
}
複製代碼
作者:
曲書辰
時間:
2019-4-27 15:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,mon=0,in,choose,out=0,peo;
re:
int a=0,b=0,c=0,d=0,h;
cout<<"「好事成雙」賽馬場"<<"第"<<n<<"場"<<endl;
cout<<"|--------------------------------------------------|"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"可用餘額為"<<mon<<endl;
cout<<"1.買入\t2.下注\t3.離開"<<endl;
cin>>choose;
if(choose==1)
{ system("cls");
cout<<"請輸入買入金額:";
cin>>in ;
mon+=in;
goto re;
}
else if(choose==2)
{ system("cls");
cout<<"請輸入下注金額:";
cin>>out;
if(mon>=out && out>=1)
{
cout<<"下注對象\ta:◆\tb:★\tc:▲\td:●:";
cin>>peo;
mon-=out;
goto start;
}else
{cout<<"錯誤";
goto re;
}
}else
{ system("cls");
goto end;
}
srand(time(NULL));
start:
system("pause");
system("cls");
while(a!=50 && b!=50 && c!=50 && d!=50)
{
cout<<"賽馬進行中"<<endl;
cout<<"|--------------------------------------------------|"<<endl;
h = rand()%4+1;
if(h==1)
a++;
if(h==2)
b++;
if(h==3)
c++;
if(h==4)
d++;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束\t";
if(a==50)
{cout<<"由◆拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<endl;
}
}
else if(b==50)
{cout<<"由★拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<endl;
}
}
else if(c==50)
{cout<<"由▲拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<endl;
}
}
else
{cout<<"由●拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<endl;
}
}
cout<<"|--------------------------------------------------|"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("pause");
system("cls");
n++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
吳孟修
時間:
2019-4-27 15:16
本帖最後由 吳孟修 於 2019-4-27 15:17 編輯
#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<<"\n可用金額:"<<money<<"元\n"<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"請買入:";
cin>>buyin;
if(buyin<0)
{
cout<<"您輸入的金額有誤,請重新買入!"<<endl;
}
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<<"比賽即將開始!\n\n";
}
else
{
cout<<"您輸入的金額有誤,請重新下注!"<<endl;
system("pause");
goto re;
}
}
else if(option==3)
{
goto end;
}
else
{
cout<<"您輸入錯誤,請重新選擇!"<<endl;
system("pause");
goto re;
}
system("pause");
system("cls");
srand(time(NULL));
while(a!=70 && b!=70 && c!=70 && d!=70)
{
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
r=rand()%4+1;
if(r==1)
{
a++;
}
if(r==2)
{
b++;
}
if(r==3)
{
c++;
}
if(r==4)
{
d++;
}
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束!由";
if(a==70)
{
cout<<"◆";
winner=1;
}
if(b==70)
{
cout<<"★";
winner=2;
}
if(c==70)
{
cout<<"▲";
winner=3;
}
if(d==70)
{
cout<<"●";
winner=4;
}
cout<<"先馳得點!"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(horse==winner)
{
money+=bet*3;
cout<<"贏了"<<bet*3<<"元!"<<endl;
}
else
{
money-=bet;
cout<<"損失"<<bet<<"元!"<<endl;
}
system("pause");
system("cls");
n++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
洪寬瀧
時間:
2019-4-27 15:17
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,f=0;
re:
int a=0,b=0,c=0,d=0,r,j,k,bet,horse,winner;
system("cls");
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額: "<<f<<"元"<<endl;
cout<<"(1)買入(2)下注(3)離開 請選擇: "<<endl;
cin>>j;
if(j==1)
{
cout<<"買入: ";
cin>>k;
f+=k;
goto re;
}else if(j==2)
{
cout<<"請下注";
cin>>bet;
if(bet>k)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet>=0 && bet<= f)
{
cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
cin>>horse;
cout<<"比賽即將開始"<<endl;
}else
{
cout<<"您輸入錯誤!!請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
goto end;
}
system("pause");
system("cls"); //清空畫面
srand(time(NULL)); //撒亂樹種子
while(a!=70 && b!=70 && c!=70&& d!=70) //判斷四隻馬只要有一隻到終點就跳離while
{
cout<<"賽馬進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
r = rand()%4+1; //產生1~4亂數 隨機挑馬1~4其中一隻
if(r==1)
a++;
if(r==2)
b++;
if(r==3)
c++;
if(r==4)
d++;
for(int i=0;i<=a;i++) //第一匹馬前進
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++) //第二匹馬前進
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++) //第三匹馬前進
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++) //第四匹馬前進
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls"); //清空畫面
}
cout<<"賽馬結束!";
if(a==70)
{
cout<<"由◆先馳得點!"<<endl;
}else if(b==70)
{
cout<<"由★先馳得點!"<<endl;
}else if(c==70)
{
cout<<"由▲先馳得點!"<<endl;
}else
{
cout<<"由●先馳得點!"<<endl;
}
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++) //第一匹馬最後的位子
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++) //第二匹馬最後的位子
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++) //第三匹馬最後的位子
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++) //第四匹馬最後的位子
{
cout<<" ";
}
cout<<"●"<<endl;
if(horse==winner)
{
f+bet*3;
}else
{
f-=bet;
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
system("cls");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-4-27 15:18
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int s=1,m=0;
re:
int a=0,b=0,c=0,d=0,r,o,z,h,W;
system("cls");
cout<<"賽馬場 第"<<s<<"局"<<endl;
cout<<"--------------------------------------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"可用餘額: "<<m<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>o;
if(o==1)
{
cout<<"買入: ";
cin>>z;
m=m+z;
goto re;
}else if(o==2)
{
cout<<"請下注: ";
cin>>z;
if(z > m)
{
cout<<"餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(z>=0 && z<= m)
{
m=m-z;
cout<<"(1)◆馬 (2)★馬 (3)▲馬 (4)●馬 請選擇:";
cin>>h;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"您輸入錯誤!!請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
goto end;
}
system("pause");
system("cls");
srand(time(NULL));
while(a!=70 && b!=70 && c!=70 && d!=70)
{
cout<<"起跑嘍~~~~~"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
r = rand()%4+1;
if(r==1)
a++;
if(r==2)
b++;
if(r==3)
c++;
if(r==4)
d++;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束! 由";
if(a==75)
{
cout<<"◆";
w = 1;
}
else if(b==75)
{
cout<<"★";
w = 2;
}
else if(c==75)
{
cout<<"▲";
w = 3;
}
else
{
cout<<"●";
w = 4;
}
cout<<"先馳得點"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(h==w)
{
m=m+(z*3);
cout<<"贏了"<<z*3<<"元!"<<endl;
}else
{
m=m-z;
cout<<"損失"<<z<<"元!"<<endl;
}
system("pause");
s++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
吳孟書
時間:
2019-4-27 15:23
本帖最後由 吳孟書 於 2019-5-4 13:19 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int t=1,m=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r,choose,in,bet,h,w;
cout<<"「好事成雙」賽馬場 第"<<t<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl<<endl;
cout<<"可用餘額:"<<m<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>choose;
if(choose==1)
{
w1:
cout<<"買入: ";
cin>>in;
if(in>0)
{
m=m+in;
goto re;
}
else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto w1;
}
}else if(choose==2)
{
cout<<"請下注:";
cin>>bet;
cout<<endl;
if(bet>m)
{
cout<<"您餘額不足,請重新輸入!"<<endl;
system("pause");
goto re;
}else if(bet>=0 && bet<= m)
{
cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
cin>>h;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
}else if(choose==3)
{
goto end;
}else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
system("pause");
system("cls");
srand(time(NULL));
while(a!=70 && b!=70 && c!=70 && d!=70)
{
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
r=rand()%4+1;
if(r==1)
{
a++;
}
if(r==2)
{
b++;
}
if(r==3)
{
c++;
}
if(r==4)
{
d++;
}
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束!由";
if(a==70)
{
cout<<"◆";
w=1;
}
else if(b==70)
{
cout<<"★";
w=2;
}
else if(c==70)
{
cout<<"▲";
w=3;
}
else if(d==70)
{
cout<<"●";
w=4;
}
cout<<"勝出!"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(h==w)
{
m=m+bet*3;
cout<<"贏了"<<bet*3<<"元"<<endl;
}else
{
m=m-bet;
cout<<"損失"<<bet<<"元"<<endl;
}
system("pause");
system("cls");
t++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
湯郡一
時間:
2019-5-4 13:18
#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;
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;
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;
cout<<"贏了"<<bet*3<<"元!"<<endl;
}else
{
money -= bet;
cout<<"損失"<<bet<<"元!"<<endl;
}
system("pause");
n++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2