標題:
[作業] 賽馬程式 (七)
[打印本頁]
作者:
方浩葦
時間:
2024-7-27 11:16
標題:
[作業] 賽馬程式 (七)
完成選項 (3)離開 的相對應程式碼
在離開時顯示戰果,譬如:
"沒輸沒贏!全身而退!"
"恭喜你!這次總共贏了100元!"
"不好意思!讓你損失了200元!"
本帖隱藏的內容需要回復才可以瀏覽
作者:
林少謙
時間:
2024-7-27 16:29
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int x,y,z,sum=0,money,money2,h,t=1,e=0;
string b[]{"◆","★","▲","●"};
re2:
int a[]{0,0,0,0};
system("cls");
cout<<"空蕩蕩賽馬場 第"<<t<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<sum<<"元"<<endl<<endl;
cout<<"<1>買入 <2>下注 <3>離開 請選擇:";
cin>>z;
if(z==1)
{
cout<<endl;
cout<<"買入: ";
cin>>money;
sum+=money;
goto re2;
}
else if(z==2&&sum>0)
{
cout<<endl;
cout<<"下注: ";
cin>>money2;
if(sum>=money2)
{
cout<<endl;
sum-=money2;
re3:
cout<<"下注幾號 <1>◆ <2>★ <3>▲ <4>● :";
cin>>h;
cout<<endl;
if(h>4||h<1)
{
cout<<"輸入錯誤 重新輸入"<<endl<<endl;
_sleep(1500);
goto re3;
}
}
else if(sum<money2)
{
cout<<"餘額不足請先買入"<<endl;
_sleep(1500);
goto re2;
}
}
else if(z==2&&sum<=0)
{
cout<<"餘額不足請先買入"<<endl;
_sleep(1500);
goto re2;
}
else if(z<=0||z>3)
{
cout<<"輸入錯誤 重新輸入";
_sleep(1500);
goto re2;
}
else if(z==3)
{
system("pause");
goto re4;
}
system("pause");
re:
if(a[0]<73&&a[1]<73&&a[2]<73&&a[3]<73)
{
system("cls");
cout<<"比賽開始"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=3; i++)
{
x=rand()%5+1;
a[i]+=x;
}
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
_sleep(100);
goto re;
}
else
{
if(a[0]>=73)
y=0;
if(a[1]>=73)
y=1;
if(a[2]>=73)
y=2;
if(a[3]>=73)
y=3;
system("cls");
cout<<"比賽結束由"<<b[y]<<"獲勝"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
}
if(y+1==h)
{
cout<<"賺到"<<money2*3<<"元"<<endl;
sum+=money2*4;
e+=money2*3;
}
if(y+1!=h)
{
cout<<"損失"<<money2<<"元"<<endl;
e-=money2;
}
system("pause");
t+=1;
goto re2;
re4:
if(e>0)
{
cout<<"恭喜你!這次總共贏了"<<e<<"元!"<<endl<<endl;
cout<<"謝謝光臨 下次還來"<<endl;
}
else if(e<0)
{
cout<<"不好意思!讓你損失了"<<-e<<"元!"<<endl<<endl;
cout<<"謝謝光臨 下次還來"<<endl;
}
else
{
cout<<"沒輸沒贏!全身而退!"<<endl<<endl;
cout<<"謝謝光臨 下次還來"<<endl;
}
cout<<
system("pause");
return 0;
}
複製代碼
作者:
李唯銘
時間:
2024-8-3 14:37
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n=1, balance=0;
int option, buying, bet, player, all;
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<<"可用餘額"<<balance<<"元"<<endl;
cout<<"請選擇 (1)買入(2)下注(3)離開"<<endl;
cin>>option;
if(option==1){
cout<<"買入 :"<<endl;
cin>>buying;
if(buying<=0){
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
balance+=buying;
all+=buying;
goto re;
}
else if(option==2){
cout<<"下注 :"<<endl;
cin>>bet;
if(bet>balance){
cout<<"餘額不足"<<endl;
_sleep(1500);
goto re;
}
if(bet<=0){
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
cout<<"請選擇 (1)◆ (2)★ (3)▲ (4)●"<<endl;
cin>>player;
cout<<"比賽即將開始"<<endl;
}
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;
cout<<"------------------------------------------------------------------------- 終點"<<endl;
for(int i=0; i<4; i++){
for(int j=0; j<s[i]; j++)
cout<<" ";
cout<<p[i]<<endl;
}
if(r+1==player){
balance+=bet*3;
cout<<"贏得"<<bet*3<<"元"<<endl;
}
else{
balance-=bet;
cout<<"損失"<<bet<<"元"<<endl;
}
system("pause");
n++;
goto re;
end:
if(all==balance){
cout<<"沒輸沒贏"<<endl;
}
if(all<balance){
cout<<"恭喜 這次賺了"<<balance-all<<"元"<<endl;
}
if(all>balance){
cout<<"可惜 這次損失"<<all-balance<<"元"<<endl;
}
cout<<"慢走"<<endl;
_sleep(1500);
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-8-3 16:27
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int x,y,z,sum=0,money,money2,h,t=1,e=0;
string b[]{"◆","★","▲","●"};
re2:
int a[]{0,0,0,0};
system("cls");
cout<<"空蕩蕩賽馬場 第"<<t<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<sum<<"元"<<endl<<endl;
cout<<"<1>買入 <2>下注 <3>離開 請選擇:";
cin>>z;
if(z==1)
{
cout<<endl;
cout<<"買入: ";
cin>>money;
sum+=money;
goto re2;
}
else if(z==2&&sum>0)
{
cout<<endl;
cout<<"下注: ";
cin>>money2;
if(sum>=money2)
{
cout<<endl;
sum-=money2;
re3:
cout<<"下注幾號 <1>◆ <2>★ <3>▲ <4>● :";
cin>>h;
cout<<endl;
if(h>4||h<1)
{
cout<<"輸入錯誤 重新輸入"<<endl<<endl;
_sleep(1500);
goto re3;
}
}
else if(sum<money2)
{
cout<<"餘額不足請先買入"<<endl;
_sleep(1500);
goto re2;
}
}
else if(z==2&&sum<=0)
{
cout<<"餘額不足請先買入"<<endl;
_sleep(1500);
goto re2;
}
else if(z<=0||z>3)
{
cout<<"輸入錯誤 重新輸入";
_sleep(1500);
goto re2;
}
else if(z==3)
{
system("pause");
goto re4;
}
system("pause");
re:
if(a[0]<73&&a[1]<73&&a[2]<73&&a[3]<73)
{
system("cls");
cout<<"比賽開始"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=3; i++)
{
x=rand()%5+1;
a[i]+=x;
}
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
_sleep(100);
goto re;
}
else
{
if(a[0]>=73)
y=0;
if(a[1]>=73)
y=1;
if(a[2]>=73)
y=2;
if(a[3]>=73)
y=3;
system("cls");
cout<<"比賽結束由"<<b[y]<<"獲勝"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
}
if(y+1==h)
{
cout<<"賺到"<<money2*3<<"元"<<endl;
sum+=money2*4;
e+=money2*3;
}
if(y+1!=h)
{
cout<<"損失"<<money2<<"元"<<endl;
e-=money2;
}
system("pause");
t+=1;
goto re2;
re4:
if(e>0)
{
cout<<"恭喜你!這次總共贏了"<<e<<"元!"<<endl<<endl;
cout<<"謝謝光臨 下次還來"<<endl;
}
else if(e<0)
{
cout<<"不好意思!讓你損失了"<<-e<<"元!"<<endl<<endl;
cout<<"謝謝光臨 下次還來"<<endl;
}
else
{
cout<<"沒輸沒贏!全身而退!"<<endl<<endl;
cout<<"謝謝光臨 下次還來"<<endl;
}
cout<<
system("pause");
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-8-4 11:36
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a=1;
int balance=0, x, money, money2, n;
re:
system("cls");
srand(time(NULL));
int s[]={0,0,0,0};
cout<<"「好事成雙」賽馬場 第 "<<a<<" 局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
{
cout<<"可用餘額:"<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>x;
if(x==1)
{
cout<<"買入: ";
cin>>money;
balance+=money;
system("cls");
goto re;
}
else if(x==2)
{
cout<<"下注: ";
cin>>money2;
if(money2>balance)
{
cout<<"輸入錯誤"<<endl;
system("pause");
system("cls");
goto re;
}
cout<<endl;
cout<<"(1)◆ (2)★ (3)▲ (4)● 請選擇:";
cin>>n;
if(n>4)
{
cout<<"輸入錯誤"<<endl;
system("pause");
system("cls");
goto re;
}
else
{
cout<<"比賽即將開始..."<<endl<<endl;
system("pause");
}
}
else if(x==3)
{
if(balance>0)
{
cout<<"恭喜你!這次總共贏了"<<balance<<"元!"<<endl<<endl;
}
else if(balance<0)
{
cout<<"不好意思!讓你損失了"<<-balance<<"元!"<<endl<<endl;
}
else
{
cout<<"沒輸沒贏!全身而退!"<<endl<<endl;
}
system("pause");
return 0;
}
else
{
cout<<"輸入錯誤"<<endl;
system("pause");
system("cls");
goto re;
}
}
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;
if(s[r]==73)
break;
_sleep(0.00000001);
}
system("cls");
cout<<"比賽結束 ";
if(s[0]==73)
cout<<"由◆先馳得點!"<<endl;
if(s[1]==73)
cout<<"由★先馳得點!"<<endl;
if(s[2]==73)
cout<<"由▲先馳得點!"<<endl;
if(s[3]==73)
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;
if(n==s[0])
{
cout<<"贏得"<<money2*3<<"元"<<endl;
balance+=money2*3;
}
if(n==s[1])
{
cout<<"贏得"<<money2*3<<"元"<<endl;
balance+=money2*3;
}
if(n==s[2])
{
cout<<"贏得"<<money2*3<<"元"<<endl;
balance+=money2*3;
}
if(n==s[3])
{
cout<<"贏得"<<money2*3<<"元"<<endl;
balance+=money2*3;
}
else
{
cout<<"損失"<<money2<<"元"<<endl;
balance-=money2;
}
system("pause");
a++;
goto re;
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-8-8 21:54
本帖最後由 陳妍蓁 於 2024-8-10 11:58 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n=0,m=0,sum=0,m1,m2,r,x;
int option1,option2;
string h[]={"◆","★","▲","●"};
int a[]={0,0,0,0};
srand(time(NULL));
re:
system("cls");
cout<<"好事成雙賽馬場 第"<<x<<"局"<<endl;
cout<<"----------------------------------------------------------------------------|終點"<<endl;
for(int i=0;i<=3;i++)
cout<<h[i]<<endl;
re2:
cout<<endl<<"可用餘額"<<m<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:"<<endl;
cin>>option1;
if(option1==1){
cout<<"(1)買入:";
cin>>m1;
cout<<"元"<<endl;
if(m1<=0){
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
m=m1++;
sum+=m1;
goto re;
}
else if (option1==2){
cout<<"下注:";
cin>>m2;
if(m2<=0 || m2>m){
cout<<"輸入錯誤"<<endl;
_sleep(1500);
goto re;
}
cout<<"請選擇:(1)◆ (2)★ (3)▲ (4)●";
cin>>option2;
cout<<"比賽即將開始..."<<endl;
}
else if(option1==3){
goto end;
}
else
goto re;
system("pause");
while(true){
system("cls");
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
r=rand()%4;
a[r]++;
_sleep(5);
for(int i=0;i<=a[0];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=a[1];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=a[2];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=a[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(a[r]==73){
break;
_sleep(50);
system("cls");
}
}
system("cls");
cout<<"比賽結束 由:"<<h[r]<<"勝出"<<endl;
cout<<"----------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a[0];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=a[1];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=a[2];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=a[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(option2==r+1){
cout<<"賺到"<<m2*3<<"元"<<endl;
m+=m2*3;
}
else{
cout<<"賠"<<m2<<"元"<<endl;
m-=m2;
}
system("pause");
r++;
goto re;
end:
if(sum==m)
cout<<"沒輸沒贏!全身而退!"<<endl<<endl;
else if(sum<m)
cout<<"恭喜你!這次總共贏了"<<m-sum<<"元!"<<endl<<endl;
else if(sum>m)
cout<<"不好意思!讓你損失了"<<sum-m<<"元!"<<endl<<endl;
cout<<"謝謝光臨,下次再來"<<endl;
_sleep(50);
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2