標題:
[隨堂測驗] 賽馬程式 (七)
[打印本頁]
作者:
鄭繼威
時間:
2023-4-1 13:14
標題:
[隨堂測驗] 賽馬程式 (七)
本帖最後由 鄭繼威 於 2023-4-8 15:28 編輯
完成選項
(3)離開
的相對應程式碼
在離開時顯示戰果,譬如:
"沒輸沒贏!全身而退!"
"恭喜你!這次總共贏了100元!"
"不好意思!讓你損失了200元!"
本帖隱藏的內容需要積分高於 1 才可瀏覽
作者:
陳宥霖
時間:
2023-4-1 14:15
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int bet=0;
int option;
int buy;
int player;
int h;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場"<<"第"<<round<<"場"<<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>>buy;
if(buy<0)
{
cout<<"輸入錯誤";
_sleep(1500);
goto re;
}
balance=balance+buy;
h=h+buy;
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<<"(1)◆(2)★(3)▲(4)● 請選擇: ";
cin>>player;
cout<<"比賽即將開始....."<<endl<<endl;
}
else if(option==3)
{
goto end;
}
else
{
goto re;
}
system("pause");
system("cls");
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;
}
cout<<endl;
if(player-1==r)
{
balance=balance+bet*3;
cout<<"贏了"<<bet*3<<"元";
}
else
{
balance=balance-bet;
cout<<"輸了"<<bet<<"元";
}
system("pause");
round++;
goto re;
end:
cout<<"不玩了"<<endl;
_sleep(1500);
if(balance==h)
{
cout<<"沒輸沒贏!全身而退!"<<endl;
_sleep(1500);
}
else if(balance>h)
{
cout<<"恭喜你!這次總共贏了"<<balance-h<<"元!"<<endl;
_sleep(1500);
}
else if(balance<h)
{
cout<<"不好意思!讓你損失了"<<h-balance<<"元!"<<endl;
_sleep(1500);
}
cout<<"歡迎光臨,下次再來 !"<<endl;
_sleep(1500);
goto re;
return 0;
}
複製代碼
作者:
林雋喆
時間:
2023-4-1 14:22
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int bet=0;
int option;
int buy;
int player;
int h;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場"<<"第"<<round<<"場"<<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>>buy;
if(buy<0)
{
cout<<"輸入錯誤";
_sleep(1500);
goto re;
}
balance=balance+buy;
h=h+buy;
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<<"(1)◆(2)★(3)▲(4)● 請選擇: ";
cin>>player;
cout<<"比賽即將開始....."<<endl<<endl;
}
else if(option==3)
{
goto end;
}
else
{
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;
}
cout<<endl;
if(player-1==r)
{
balance=balance+bet*3;
cout<<"贏了"<<bet*3<<"元";
}
else
{
balance=balance-bet;
cout<<"輸了"<<bet<<"元";
}
system("pause");
round++;
goto re;
end:
cout<<"88"<<endl;
_sleep(1500);
if(balance==h){
cout<<"沒輸沒贏!全身而退!"<<endl;
_sleep(1500);
}
else if(balance>h)
{
cout<<"恭喜你!這次總共贏了"<<balance-h<<"元!"<<endl;
_sleep(1500);
}
else if(balance<h)
{
cout<<"不好意思!讓你損失了"<<h-balance<<"元!"<<endl;
_sleep(1500);
}
cout<<"歡迎光臨,下次再來 !"<<endl;
_sleep(1500);
goto re;
return 0;
}
複製代碼
作者:
宜儒
時間:
2023-4-1 14:23
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1; //局數
int balance=0; //餘額
int option; //選項
int buy, bet, player;
// 買入 下注 賭哪隻馬
int total=0; //總共買入
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0}; //存放進度用的
string p[]={"◆","★","▲","●"}; //存放馬用的
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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;
//輸入等於1執行買入(儲值)
if(option==1){
//買入
cout<<"買入: ";
cin>>buy;
if(buy<=0){
//如果買入小於0
cout<<"輸入錯誤!";
_sleep(1500); //顯示1.5秒
goto re;
}
balance=balance+buy; //儲值
total=total+buy;
goto re;
}
//輸入等於2執行下注
else if(option==2)
{
cout<<"下注: ";
cin>>bet;
if(bet<=0)
{
//如果小於0
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
if(bet>balance)
{
//下注錢大於可用餘額代表錢不夠
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
//OK選馬
cout<<endl<<"(1)◆ (2)★ (3)▲ (4)● 請選擇: ";
cin>>player;
cout<<"比賽即將開始..."<<endl<<endl;
}
//輸入等於3結束
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
system("pause");
system("cls"); //清空畫面
while(s[r]<=73) //開始賽馬
{
r=rand()%4; //0~3 (抽馬)
s[r]++; //看電腦抽到哪隻馬就+1
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(player-1==r){
balance=balance+bet*3;
cout<<"贏了"<<bet*3<<"元!";
}
else{
balance=balance-bet;
cout<<"損失"<<bet<<"元!";
}
system("pause");
round++; //局數+1
goto re;
end:
if(total>balance)
{
cout<<"不好意思!讓你損失了"<<total-balance<<"元!";
}
else if(total=balance)
{
cout<<"沒輸沒贏!下次再來喔!";
}
else
{
cout<<"恭喜你!贏了"<<balance-total<<"元!";
}
cout<<endl<<"不玩了? 88~"<<endl;
_sleep(1500);
return 0;
}
複製代碼
作者:
楊芊琦
時間:
2023-4-1 14:24
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int steps[] = { 0,0,0,0 };
string shape[] = { "◆","★","▲","●" };
int round = 0, balance = 0, choose, horse,plus,lost=0,win=0,num=0;
int w=0,ran;
re:
system("cls");
cout << "馬場大廳-----------" << endl;
cout << "馬荷包餘額:" << balance<<"\n<1> 儲值 <2>下注 <3>離開\n請選擇:";
cin >> choose;
switch (choose)
{
case 1:
cout << "請輸入儲值金額:";cin >> plus;
if (plus <= 0)
{
cout << "輸入錯誤,即將返回大廳" << endl;
_sleep(1500);
goto re;
}
balance += plus;plus = 0;
cout << "已儲值" << endl;
goto re;
break;
case 2:
cout << "請選擇下注金額:";cin >> plus;
lost+=plus;
if (plus > balance||plus<=0)
{
cout << "輸入錯誤,即將返回大廳" << endl;
_sleep(1500);
goto re;
}
cout << "<1>◆ <2>★ <3>▲ <4>●\n請選擇馬匹:";cin >> horse;
if (horse >= 5 || horse <= 0)
{
cout << "輸入錯誤,即將返回大廳" << endl;
_sleep(1500);
goto re;
}
horse = horse - 1;
break;
case 3:
num=-lost+win;
if(num<0)
cout<<"你今天共陪了:"<<-num<<"元"<<endl;
else
cout << "你的馬錢包金額" << balance << "元已轉至你的錢包\n" << endl;
system("pause");
return 0;
}
cout << "超坑錢賽馬場" << endl;
cout << "-------------------------------------------------------------------------|終點";
_sleep(2000);
while (w <= 71)
{
cout << "比賽進行中" << endl;
cout << "-------------------------------------------------------------------------|終點" << endl;
steps[rand() % 4] += 1;
ran = rand() % 4;
w = steps[ran];
for (int u = 0;u <= 3;u++)
{
for (int s = 0;s <= steps[u];s++)
{
cout << " ";
}
cout << shape[u] << endl;
}
_sleep(1);
if (w == 71)
{
cout << shape[ran] << "勝利!\n" << endl;
if (ran == horse)
{
cout << "你選擇的馬匹勝利了!\n" << "你共下注了:" << plus << "元\n恭喜賺了"
<< plus * 9 << "元" << endl;
balance += plus * 10;
win+=plus*10;
plus = 0;
_sleep(2000);
goto re;
}
else
{
cout << "你選擇的馬匹並沒有贏...\n" << "你共賠了:" << plus << "元" << endl;
balance -= plus;lost+=plus;plus=0;
_sleep(2000);
goto re;
}
}
system("cls");
}
}
複製代碼
作者:
羅暐傑
時間:
2023-4-1 14:33
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
int round=1;
int balance=0;
int money=0;
int betmoney=0;
int player=0;
int moneylost=0;
int moneygained=0;
re:
system("cls");
srand(time(NULL));
string p[]={"◆","★","▲","●"};
int s[]={0,0,0,0};
int r=0;
int choice;
cout<<"歡迎光臨騙你錢賽馬場 | 賽馬第"<<round<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
cout<<p[i]<<endl;
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入(儲值) (2)下注 (3)離開 請選擇:";
cin>>choice;
if(choice==1){
cout<<"請問要加值多少錢:";
cin>>money;
if(money<=0){
cout<<"輸入錯誤,請重新輸入!"<<endl;
_sleep(1500);
goto re;
}else
balance=balance+money;
goto re;
}else if(choice==2){
cout<<"請問要下注多少錢:";
cin>>betmoney;
if (betmoney<=0 or betmoney>balance){
cout<<"輸入錯誤,請重新輸入!"<<endl;
_sleep(1500);
goto re;
}else{
cout<<"(1)◆(2)★(3)▲(4)●請選擇:";
}
cin>>player;
if (player==1 or player==2 or player==3 or player==4){
cout<<"比賽即將開始"<<endl;
_sleep(2000);
}else{
cout<<"輸入錯誤,請重新輸入!"<<endl;
_sleep(1500);
goto re;
}
}
if(choice == 3){
if (moneylost>0 and moneylost>moneygained){
cout<<"不好意思!讓你損失了"<<moneylost-moneygained<<"元!"<<endl;
cout<<"歡迎下次再來!"<<endl;
}else if (moneygained>0 and moneylost<moneygained){
cout<<"恭喜你!這次總共贏了"<<moneygained-moneylost<<"元!"<<endl;
cout<<"歡迎下次再來!"<<endl;
}else if (moneygained=moneylost){
cout<<"沒輸沒贏!全身而退!"<<endl;
cout<<"歡迎下次再來!"<<endl;
}else{
cout<<"歡迎下次再來!"<<endl;
}
system("pause");
return 0;
}
system("pause");
system("cls");
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;
}
system("cls");
}
cout<<"比賽結束!由"<<p[r]<<"獲勝!"<<endl;
if (player-1 == r){
cout<<"你下注的馬贏了!恭喜你贏得"<< betmoney*3<<"元!"<<endl;
balance+=betmoney*2;
moneygained+=betmoney*2;
}else{
moneylost+=betmoney;
balance-=betmoney;
cout<<"你下注的馬輸了!, 損失"<<betmoney<<"元"<<endl;
}
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<4; i++)
{
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
round++;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
翁川祐
時間:
2023-4-1 14:33
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int option;
int buy, bet, player;
int j=0;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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>>buy;
if(buy<=0){
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance=balance+buy;
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");
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(25);
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;
}
cout<<endl;
if(player-1==r){
balance=balance+bet*3;
cout<<"賺了"<<bet*3<<"元"<<endl;
j=j+bet*3;
}
else{
balance=balance-bet;
cout<<"損失"<<bet<<"元"<<endl;
j=j-bet;
}
system("pause");
round++;
goto re;
end:
cout<<endl<<"遊戲結束"<<endl;
if(j==0){
cout<<"沒輸沒贏!全身而退!"<<endl;
}
else if(j>0){
cout<<"恭喜你!這次總共贏了"<<j<<"元!"<<endl;
}
else{
cout<<"不好意思!讓你損失了"<<j<<"元!"<<endl;
}
_sleep(1500);
return 0;
}
複製代碼
作者:
徐啟祐
時間:
2023-4-1 14:34
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1,balance=0,used=0;
int option,buy,bet,player;
re:
system("cls");
srand(time(NULL));
string p[]={"◆","★","▲","●"};
int s[]={0,0,0,0};
int r=0;
cout<<"「好事成霜」賽馬場 第"<<round<<"局"<<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<<endl<<"買入: ";
cin>>buy;
if(buy<=0){
cout<<"輸入錯誤";
_sleep(1500);
goto re;
}
balance=balance+buy;
goto re;
}
else if(option==2){
cout<<endl<<"要下注多少: ";
cin>>bet;
if(bet<=0){
cout<<"輸入錯誤";
_sleep(1500);
goto re;
}
else if(bet>balance){
cout<<"可用餘額不足,請先買入!";
_sleep(1500);
goto re;
}
else
cout<<"(1)◆(2)★(3)▲(4)● 請選擇:";
cin>>player;
player=player-1;
goto start;
}
else if(option==3){
goto end;
}
else
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
start:
cout<<"準備開始比賽"<<endl<<endl;
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(10);
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(player<r or player>r)
{
balance-=bet;
cout<<"損失"<<bet<<"元"<<endl<<endl;
used=used-bet;
}
else
{
cout<<"恭喜贏得"<<bet*3<<"元"<<endl<<endl;
balance+=bet*3;
used=used+bet*3;
}
system("pause");
round++;
goto re;
end:
if(used>0)
cout<<"恭喜你!這次總共贏了"<<used<<"元!"<<endl;
else if(used<0)
cout<<"不好意思!讓你損失了"<<-used<<"元!"<<endl;
else
cout<<"沒輸沒贏!全身而退!"<<endl;
_sleep(1500);
system("pause");
return 0;
}
複製代碼
作者:
羅紹齊
時間:
2023-4-1 14:37
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int option;
int buy, bet, player;
int earn;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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>>buy;
if(buy<=0){
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance=balance+buy;
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");
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(20);
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;
}
cout<<endl;
if(player-1==r){
balance=balance-bet*3;
cout<<"贏了"<<bet*3<<"元"<<endl;
earn=earn+bet*3;
}
else{
cout<<"輸了"<<bet<<"元"<<endl;
earn=earn-bet;
}
system("pause");
round++;
goto re;
end:
if(earn>0)
cout<<"恭喜賺"<<earn<<"元"<<endl;
else if(earn<0)
cout<<"可憐賠"<<-earn<<"元"<<endl;
else
cout<<"不賺不賠,好玩~"<<endl;
cout<<endl<<"不玩了? 88~"<<endl;
_sleep(1500);
return 0;
}
複製代碼
作者:
葉佳和
時間:
2023-4-1 14:41
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1; //局數
int balance=0; //餘額
int option;
int jk=0 ; //選項
int buy,player,bet; //儲值金額
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0}; //存放進度用的
string p[]={"◆","★","▲","●"}; //存放馬用的
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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>>buy;
balance=balance+buy;
//儲值
goto re;
}
else if(option==3)
{
goto end;
}
else if(option==2){
cout<<"下注對象:";
cin>>player;
cout<<"下注金額:";
cin>>bet;
if(bet>balance){
cout<<"error"<<endl;
_sleep(500);
goto re;
}
}
//輸入等於1執行買入(儲值)
else if(option>3 || option<1)
{
cout<<"錯誤"<<endl;
cout<<"請重新輸入"<<endl;
_sleep(500);
goto re;
}
system("pause");
system("cls"); //清空畫面
while(s[r]<=73) //開始賽馬
{
r=rand()%4; //0~3 (抽馬)
s[r]++; //看電腦抽到哪隻馬就+1
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(r==player-1){
cout<<"u win"<<endl;
balance=balance+bet*3;
cout<<"stonks+"<<bet*3<<endl;
jk=jk+bet*3;
}
else
{
cout<<"u lose lol"<<endl;
balance=balance-bet;
cout<<"-"<<bet<<endl;
jk=jk-bet;
}
system("pause");
round++; //局數+1
goto re;
end:
if(jk<0)
cout<<"lol lose "<<-jk<<endl;
else if(jk>0)
cout<<"oh shit u win "<<jk<<endl;
else
cout<<"洴艏"<<endl;
cout<<"88"<<endl;
_sleep(1000);
return 0;
}
複製代碼
作者:
吳俊頡
時間:
2023-4-1 14:42
[code]#include<ios
tream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int bet=0;
int option;
int buy;
int player;
int h;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"豬","馬","牛","羊"};
int r=0;
cout<<"可憐啊!賽馬場 "<<"第"<<round<<"場"<<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>>buy;
if(buy<0)
{
cout<<"輸入錯誤";
_sleep(1500);
goto re;
}
balance=balance+buy;
h=h+buy;
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<<"(1)豬","(2)馬","(3)牛","(4)羊 請選擇: ";
cin>>player;
cout<<"比賽即將開始....."<<endl<<endl;
}
else if(option==3)
{
goto end;
}
else
{
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;
}
cout<<endl;
if(player-1==r)
{
balance=balance+bet*3;
cout<<"贏了"<<bet*3<<"元";
}
else
{
balance=balance-bet;
cout<<"輸了"<<bet<<"元";
}
system("pause");
round++;
goto re;
end:
cout<<"不玩了"<<endl;
_sleep(1500);
if(balance==h)
{
cout<<"沒輸沒贏!全身而退!"<<endl;
_sleep(1500);
}
else if(balance>h)
{
cout<<"恭喜你!這次總共贏了"<<balance-h<<"元!"<<endl;
_sleep(1500);
}
else if(balance<h)
{
cout<<"不好意思!讓你損失了"<<h-balance<<"元!"<<endl;
_sleep(1500);
}
cout<<"歡迎光臨,下次再來 !"<<endl;
_sleep(1500);
goto re;
return 0;
}
複製代碼
[/code]
作者:
陳牧謙
時間:
2023-4-8 13:18
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int round=1;
int balance=0;
int earn,option,buy, bet, player;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
string p[]={"◆","★","▲","●"};
int r=0;
cout<<"「好事成雙」賽馬場 第"<<round<<"局"<<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>>buy;
if(buy<=0){
cout<<"輸入錯誤!";
_sleep(1500);
goto re;
}
balance=balance+buy;
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");
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(20);
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;
}
cout<<endl;
if(player-1==r){
balance=balance-bet*3;
cout<<"贏了"<<bet*3<<"元"<<endl;
earn=earn+bet*3;
}
else{
cout<<"輸了"<<bet<<"元"<<endl;
earn=earn-bet;
}
system("pause");
round++;
goto re;
end:
if(earn>0)
cout<<"恭喜您賺了"<<earn<<"元"<<endl;
else if(earn<0)
cout<<"對不起,你賠了"<<-earn<<"元"<<endl;
else
cout<<"不賺不賠,好玩~"<<endl;
cout<<endl<<"不玩了? 88~"<<endl;
_sleep(1500);
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2