標題:
[作業] 賽馬程式 (五)
[打印本頁]
作者:
方浩葦
時間:
2024-7-13 07:28
標題:
[作業] 賽馬程式 (五)
1. 完成主選單的主要架構 (運用if...else if...else判斷式)
2. 新增 (2)下注 功能
3. 處理
下注
時可能出現的bug: 當輸入0以下的數字, 顯示 "
輸入錯誤!
"
4. 處理
下注
時可能出現的bug: 當下注金額超過可用餘額, 顯示 "
可用餘額不足,請先買入!
"
5. 處理
買入
時可能出現的bug: 當輸入0以下的數字, 顯示 "
輸入錯誤!
"
6. 錯誤提示訊息顯示 1.5秒 後自動消失, 並回到輸入畫面, 使能重新輸入
本帖隱藏的內容需要回復才可以瀏覽
作者:
邱博宥
時間:
2024-8-17 18:02
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
int e=0;
int b,d,g,h,money=0;
srand(time(NULL));
re:
e++;
start:
system("cls");
int a[4]= {0,0,0,0};
string j[4]= {"△","▲","☆","★"};
cout<<"賽馬場"<<"第"<<e<<"局"<<endl;
cout<<"---------------------------------------------------------|終點"<<endl;//57
cout<<"△"<<endl;
cout<<"▲"<<endl;
cout<<"☆"<<endl;
cout<<"★"<<endl;
cout<<endl<<endl<<"你的餘額:"<<money<<endl;
cout<<"[1]買入[2]下注[3]離開:";
cin>>d;
if(d==1)
{
cout<<"你要買入多少錢?:";
cin>>b;
if(b<0)
{
cout<<"輸入錯誤";
_sleep(1500);
goto start;
}
money+=b;
goto start;
}
if(d==2)
{
cout<<"下注:";
cin>>g;
if(g>money)
{
cout<<"輸入錯誤";
_sleep(1500);
goto start;
}
if(g<0)
{
cout<<"輸入錯誤";
_sleep(1500);
goto start;
}
cout<<"請選擇1△ 2▲ 3☆ 4★: ";
cin>>h;
}
system("pause");
system("cls");
while(true)
{
system("cls");
int c=rand()%4;
if(a[c]>=57)
{
cout<<"賽馬場"<<"第"<<e<<"局"<<"由"<<j[c]<<"先馳得點"<<endl;
break;
}
cout<<"賽馬場"<<"第"<<e<<"局"<<endl;
cout<<"---------------------------------------------------------|終點"<<endl;
a[c]+=3;
for(int m=1; m<=a[0]; m++)
cout<<" ";
cout<<"△"<<endl;
for(int m=1; m<=a[1]; m++)
cout<<" ";
cout<<"▲"<<endl;
for(int m=1; m<=a[2]; m++)
cout<<" ";
cout<<"☆"<<endl;
for(int m=1; m<=a[3]; m++)
cout<<" ";
cout<<"★"<<endl;
_sleep(50);
}
cout<<"---------------------------------------------------------|終點"<<endl;
for(int m=1; m<=a[0]; m++)
cout<<" ";
cout<<"△"<<endl;
for(int m=1; m<=a[1]; m++)
cout<<" ";
cout<<"▲"<<endl;
for(int m=1; m<=a[2]; m++)
cout<<" ";
cout<<"☆"<<endl;
for(int m=1; m<=a[3]; m++)
cout<<" ";
cout<<"★"<<endl;
system("pause");
system("cls");
goto re;
return 0;
}
複製代碼
作者:
鄭豊翰
時間:
2024-9-7 11:03
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int s[]={0,0,0,0};
string k[]={"◆","★","▲","●"};
int o, r, balance=0, option, buyin, bet, contestant;
re:
o++;
be:
system("cls");
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第"<<o<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl<<endl;
option=0;
cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"<1>買入 <2>下注 <3>離開 請選擇: ";
cin>>option;
if(option==1){
cout<<"買入: ";
cin>>buyin;
if(buyin<=0){
cout<<"輸入錯誤";
_sleep(1500);
goto be;
}
else{
balance+=buyin;
goto be;}
}
else if(option==2){
cout<<"下注: ";
cin>>bet;
if(bet > balance){
cout<<"餘額不足!!請買入"<<endl;
_sleep(1500);
goto be;
}
else if (bet>0 && bet<=balance){
cout<<"<1>◆ <2>★ <3>▲ <4>● 請選擇: ";
cin>>contestant;
}
else{
cout<<"輸入錯誤";
_sleep(1500);
goto be;
}
}
else if(option==3){
goto end;
}
else{
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto be;
}
system("pause");
while(true)
{
system("cls");
r=rand()%4;
s[r]++;
cout<<"比賽進行中 第"<<o<<"局"<<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(s[r]==73)
break;
_sleep(50);
}
system("cls");
cout<<"比賽結束 由"<<k[r]<<"獲勝"<<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(contestant - 1 == r){
cout<<"你獲得"<<bet*3<<"元"<<endl;
balance+=(bet*3);
}
else{
cout<<"你輸了"<<bet<<"元"<<endl;
balance-=bet;
}
cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"<1>買入 <2>下注 <3>離開 請選擇: ";
cin>>option;
system("pause");
goto re;
end:
cout<<"Bye Bye";
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2