標題:
賽馬程式 (五)
[打印本頁]
作者:
陳品肇
時間:
2018-12-15 00:23
標題:
賽馬程式 (五)
本帖最後由 陳品肇 於 2019-1-5 16:05 編輯
1. 完成主選單的主要架構 (運用if...else if...else判斷式)
2. 新增 (2)下注 功能
#include<iostream>
[code]#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,money=0;
re1:
int a=0, b=0, c=0, d=0, r,option,buying,bet;
system("cls");
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl<<endl;
cout<<"可用餘額: "<< money<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1) //選擇買入多少籌碼
{
cout<<"買入:";
cin>>buying;
money = money + buying; // 原始的餘額加上買入的籌碼
goto re1;
}else if(option==2)
{
if(money==0) //一開始就沒有餘額
{
cout<<"可用餘額不足!請先買入!"<<endl;
system("pause");
goto re1;
}
cout<<"下注:";
cin>> bet;
if(bet>money) //餘額< 下注金額
{
cout<<"可用餘額不足!請先買入!"<<endl;
system("pause");
goto re1;
}else if(bet < money)
{
cout<<"(1)◆(2)★(3)▲(4)● 請選擇: "<<endl;
cin>>option;
cout<<"比賽即將開始..."<<endl<<endl;
system("pause");
}
}else if(option==3)
{
goto end;
}else
{
cout<<"輸入錯誤!!"<<endl;
system("pause");
goto re1;
}
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<<"◆";
}
else if(b==75)
{
cout<<"★";
}
else if(c==75)
{
cout<<"▲";
}
else
{
cout<<"●";
}
cout<<" 先馳得點!"<<endl;
// 印出最後4匹馬的結果
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("pause");
n++;
goto re1;
end:
system("pause");
return 0;
}
複製代碼
作者:
譚詩澐
時間:
2018-12-15 17:21
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int balance=0;
start:
srand(time(NULL));
int space[]={0,0,0,0};
int option, money;
system("cls");
cout<<"賽馬場"<<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>>money;
balance+=money; //balance=balance+buyin
goto start;
}
int tmp;
cout<<"下注:";
cin>>tmp;
if (tmp>money)
{
cout<<"可用餘額不足!請先買入"<<endl;
system("pause");
goto start;
}else if(tmp<money)
{
cout<<"(1)◆ (2)★ (3)▲ (4)●請選擇: "<<endl;
}
system("pause");
while (true)
{
int r=rand()%4;
space[r]++;
if(space[r]==74)
break;
cout<<"比賽進行中"<<endl;
cout<<"--------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=space[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int j=0;j<=space[1]; j++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int j=0;j<=space[2];j++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int j=0;j<=space[3];j++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束! 由 ";
if(space[0]==74)
cout<<"◆";
else if(space[1]==74)
cout<<"★";
else if(space[2]==74)
cout<<"▲";
else
cout<<"●";
cout<<" 先到達終點!"<<endl;
cout<<"比賽結束"<<endl;
cout<<"--------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=space[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int j=0;j<=space[1]; j++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int j=0;j<=space[2];j++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int j=0;j<=space[3];j++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("pause");
goto start;
system("pause");
return 0;
}
複製代碼
作者:
蔡依宸
時間:
2018-12-15 17:22
#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, buy;
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>>buy;
money+=buy;
goto re;
}
else if(option==2)
{
if(money==0)
{
cout<<"你沒錢啦,窮B"<<endl;
system("pause");
goto re;
}
int tmp;
cout<<"下注:";
cin>> tmp;
if(tmp>money) //餘額< 下注金額
{
cout<<"到底有沒有錢!傻B!"<<endl;
system("pause");
goto re;
}else if(tmp < money)
{
cout<<"(1)◆(2)★(3)▲(4)● 請選擇: "<<endl;
cin>>option;
}
}
else if(option==3)
{
goto end;
}else
{
cout<<"白癡喔"<<endl;
system("pause");
goto re;
}
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<<"◆";
else if(b==75)
cout<<"★";
else if(c==75)
cout<<"▲";
else
cout<<"●";
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("pause");
n++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
陳柏霖
時間:
2018-12-15 17:25
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x=1 ,mony=0 ,many;
re:
int a=0 ,b=0 ,c=0 ,d=0 ,z;
string n[]={"◆","★","㊣","▼"};
srand(time(NULL));
cout<<"第"<<x<<"場[萬事如意]賽馬場"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"㊣"<<endl;
cout<<"▼"<<endl<<endl;
cout<<"可用餘額:"<<mony<<"元"<<endl;
cout<<"(1)買入(2)下注(3)離開 請選擇:";
cin>>many;
if(many==1)
{
int tim;
cout<<"買入:";
cin>>tim;
mony=mony+tim;
system("cls");
goto re;
}else if(many==2)
{
int tim;
if(mony==0)
{
cout<<"餘額不足!請先買入!";
system("pause");
system("cls");
goto re;
}
cout<<"下注:";
cin>>tim;
if(tim>mony)
{
cout<<"餘額不足!請先買入!";
system("pause");
system("cls");
goto re;
}else if(tim>mony)
{
cout<<"(1)■(2)★(3)㊣(4)▼ 請選擇:";
cin>>many;
cout<<"比賽即將開始>>>"<<endl<<endl;
system("pause");
}
}else if(many==3)
{
goto go;
}else
{
cout<<"輸入錯誤";
system("pause");
system("cls");
goto re;
}
system("pause");
while(a!=70 && b!=70 && c!=70 && d!=70)
{
cout<<"比賽中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
z=rand()%4+1;
if(z==1)
{
a+=2;
}
if(z==2)
{
b+=2;
}
if(z==3)
{
c+=2;
}
if(z==4)
{
d+=2;
}
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<<"第"<<x<<"場比賽結束 由"<<n[z-1]<<"先馳得點!"<<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;
cout<<"按任意鍵進行下一場比賽"<<endl;
system("pause");
system("cls");
x++;
goto re;
go:
system("pause");
return 0;
}
複製代碼
作者:
戴安利
時間:
2018-12-15 17:36
#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;
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)離開 請選擇"<<endl;
cin>>option;
if(option==1)
{
cout<<"買入:"<<endl;
cin>>buyin;
money+=buyin;
goto re;
}
else if(option==2)
{
if(money==0)
{
cout<<"可用餘額不足!請先買入!!"<<endl;
system("pause");
goto re;
}
int tmp;
cout<<"下注:";
cin>>tmp;
if(tmp>money)
{
cout<<"可用餘額不足!請先買入!!"<<endl;
system("pause");
goto re;
}
else if(tmp<money)
{
cout<<"(1)◆(2)★(3)▲(4)● 請選擇:"<<endl;
}
else if(option==3)
{
goto end;
}
else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
system("pause");
system("cls");
srand(time(NULL));
while(a!=20 && b!=20 && c!=20 && d!=20)
{
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;
a++;
for(int i=0;i<=b;i++)
cout<<" ";
cout<<"★"<<endl;
b++;
for(int i=0;i<=c;i++)
cout<<" ";
cout<<"▲"<<endl;
c++;
for(int i=0;i<=d;i++)
cout<<" ";
cout<<"●"<<endl;
d++;
system("cls");
}
cout<<"賽馬結束...!由 ";
if(a==20)
cout<<"◆";
else if(b==20)
cout<<"★";
else if(c==20)
cout<<"▲";
else
cout<<"●";
cout<<"先抵達終點!"<<endl;
cout<<"-------------------------------------------|終點"<<endl;
for(int i=0;i<=a;i++)
cout<<" ";
cout<<"◆"<<endl;
a++;
for(int i=0;i<=b;i++)
cout<<" ";
cout<<"★"<<endl;
b++;
for(int i=0;i<=c;i++)
cout<<" ";
cout<<"▲"<<endl;
c++;
for(int i=0;i<=d;i++)
cout<<" ";
cout<<"●"<<endl;
d++;
system("pause");
n++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
戴唯陞
時間:
2018-12-15 17:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,balance=0;
re1:
int a=0, b=0, c=0, d=0, r,option,;
system("cls");
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"剩餘金額"<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 選擇:"<<endl;
cin>>option;
if(option==1)
{
int tmp;
cout<<"買入";
cin>>tmp;
balance=balance+tmp;
goto re1;
}else if(option==2)
{
if (balance==0)
{
cout<<"餘額不足,請先買入"<<endl;
system("pause");
goto re1;
}
int tmp;
cout<<"下注";
cin>>tmp;
if (tmp>balance)
if (tmp<balance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇 "<endl;
}
}else if(option==3)
{
goto end;
}else
{
cout<<"輸入錯誤!!"<<endl;
system("pause");
goto re1;
}
system("pause");
system("cls");
srand(time(NULL));
while(a!=60 && b!=60 && c!=60 && d!=60)
{
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==60)
cout<<"◆";
else if(b==60)
cout<<"★";
else if(c==60)
cout<<"▲";
else
cout<<"●";
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("pause");
n++;
goto re1;
end:
system("pause");
return 0;
}
複製代碼
作者:
戴偉宸
時間:
2018-12-15 17:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,balance=0;
re:
int a=0,b=0,c=0,d=0,r,option,buyin;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
int tmp;
cout<<"買入:";
cin>>buyin;
balance+=buyin;
goto re;
}
else if(option==2)
{
if(balance==0)
{
cout<<"可用餘額不足!請先買入!"<<endl;
system("pause");
goto re;
}
else if(balance>0)
{
cout<<"下注"<<tmp<<"元"<<endl;
cin>>tmp;
if(tmp>balance)
{
cout<<"可用餘額不足!請先買入!"<<endl;
system("pause");
goto re;
}
else if(tmp<balance)
{
cout<<"(1)◆(2)★(3)▲(4)● 請選擇:"<<endl;
cin>>option;
cout<<"比賽即將開始..."<<endl<<endl;
system("pause");
}
}
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<<"賽馬結束"<<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;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"由";
if(a==70)
{
cout<<"◆";
}
else if(b==70)
{
cout<<"★";
}
else if(c==70)
{
cout<<"▲";
}
else if(d==70)
{
cout<<"●";
}
cout<<"先馳得點"<<endl<<endl;
system("pause");
system("cls");
n++ ;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蔡季庭
時間:
2018-12-15 17:39
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n=1 , money=0;
re1:
int r,option,buyin;
int space[4]={0,0,0,0};
string name[4]={"◆","★","▲","●"};
srand(time(NULL));
system("cls");
cout<<"[好棒棒]賭賽馬場"<<"第"<<n<<"局"<<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=money+buyin;
goto re1;
}else if(option==2)
{
if(money==0)
{
cout<<"可用餘額不足!請先買入!"<<endl;
system("pause");
goto re1;
}
int tmp;
cout<<"下注:";
cin>> tmp;
if(tmp>money)
{
cout<<"可用餘額不足!請先買入!"<<endl;
system("pause");
goto re1;
}else if(tmp <= money)
{
cout<<"(1)◆(2)★(3)▲(4)● 請選擇: "<<endl;
cin>>option;
cout<<"比賽即將開始..."<<endl<<endl;
system("pause");
}
}else if(option==3)
{
goto end;
}else
{
cout<<"輸入錯誤!!"<<endl;
system("pause");
goto re1;
}
system("cls");
system("pause");
while(true)
{
r=rand()%4;
space[r]++;
if(space[r]==34)
break;
cout<<"比賽進行中"<<endl;
cout<<"----------------------------------|終點"<<endl;
for(int j=0;j<space[0];j++)
cout<<" ";
cout<<"◆"<<endl;
for(int j=0;j<space[1];j++)
cout<<" ";
cout<<"★"<<endl;
for(int j=0;j<space[2];j++)
cout<<" ";
cout<<"▲"<<endl;
for(int j=0;j<space[3];j++)
cout<<" ";
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束"<<endl;
cout<<"----------------------------------|終點"<<"由"<<name[r]<<"先馳得點"<<endl;
for(int j=0;j<space[0];j++)
cout<<" ";
cout<<"◆"<<endl;
for(int j=0;j<space[1];j++)
cout<<" ";
cout<<"★"<<endl;
for(int j=0;j<space[2];j++)
cout<<" ";
cout<<"▲"<<endl;
for(int j=0;j<space[3];j++)
cout<<" ";
cout<<"●"<<endl;
n++;
goto re1;
end:
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2