標題:
賽馬程式 (四)
[打印本頁]
作者:
陳品肇
時間:
2019-4-27 13:12
標題:
賽馬程式 (四)
本帖最後由 陳品肇 於 2019-4-27 13:46 編輯
加入首頁選單, 新增買入的功能, 執行畫面如下:
可用餘額: 0 元
(1)買入 (2)下注 (3)離開 請選擇: 1
買入: 200
在使用者輸入數值後, 畫面更新如下:
可用餘額: 200 元
(1)買入 (2)下注 (3)離開 請選擇:
#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;
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)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
balance+=buyin; //balance=balance+buyin
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;
system("pause");
return 0;
}
複製代碼
作者:
章幼莛
時間:
2019-4-27 13:53
#include<iostream>
#include<cstdlib>
#include <time.h>
using namespace std;
int main()
{
int g=1,rest=0;
re:
int a=0,b=0,c=0,d=0,h,option,buyin=0;
cout<<"「好事成雙」賽馬場 第"<<g<<"局"<<endl;
cout<<"|--------------------------------------------------|"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"可用餘額"<<rest<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入金額:"<<buyin;
cin>>buyin;
rest+=buyin;
goto re;
}else if(option==2)
{}else if(option==3)
{}else
{
cout<<"輸入錯誤"<<endl;
goto re;
}
system("pause");
srand(time(NULL));
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");
}
if(a==50)
{
cout<<"比賽結束 由◆先馳得點"<<endl;
}
if(b==50)
{
cout<<"比賽結束 由★先馳得點"<<endl;
}
if(c==50)
{
cout<<"比賽結束 由▲先馳得點"<<endl;
}
if(d==50)
{
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;
system("pause");
system("cls");
g++;
goto re;
system("pause");
return 0;
}
複製代碼
回復
1#
陳品肇
作者:
洪寬瀧
時間:
2019-4-27 13:56
#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;
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;
}
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;
n++; //加一場
system("pause");
system("cls");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-4-27 13:58
#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;
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;
}
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<<"比賽結束!";
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;
s++;
system("pause");
system("cls");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
湯郡一
時間:
2019-4-27 14:00
#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, buyin;
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)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
balance+=buyin; //balance=balance+buyin
goto re1;
}
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 re1;
system("pause");
return 0;
}
複製代碼
作者:
吳孟修
時間:
2019-4-27 14:02
#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;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"可用金額:"<<money<<"元"<<endl;
f:
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
money+=buyin;
goto re;
}
/*else if(option==2)
{}
else if(option==3)
{}*/
else
{
cout<<"輸入錯誤"<<endl;
goto f;
}
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<<"◆";
}
if(b==70)
{
cout<<"★";
}
if(c==70)
{
cout<<"▲";
}
if(d==70)
{
cout<<"●";
}
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;
system("pause");
system("cls");
n++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
吳孟書
時間:
2019-4-27 14:02
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int t=1,m=0;
re:
int a=0,b=0,c=0,d=0,r,choose,in;
cout<<"「好事成雙」賽馬場 第"<<t<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"可用餘額:"<<m<<"元"<<endl;
w1:
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>choose;
if(choose==1)
{
cout<<"買入: ";
cin>>in;
m=m+in;
goto re;
}else if(choose==2)
{
}else if(choose==3)
{
}else
{
cout<<"輸入錯誤"<<endl;
goto w1;
}
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<<"◆";
}
else if(b==70)
{
cout<<"★";
}
else if(c==70)
{
cout<<"▲";
}
else if(d==70)
{
cout<<"●";
}
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;
system("pause");
system("cls");
t++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曲書辰
時間:
2019-4-27 14:06
本帖最後由 曲書辰 於 2019-4-27 14:44 編輯
#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<<"由◆拿下勝利"<<endl;
if(b==50)
cout<<"由★拿下勝利"<<endl;
if(c==50)
cout<<"由▲拿下勝利"<<endl;
if(d==50)
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;
system("pause");
system("cls");
n++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
王瑞喻
時間:
2019-5-4 14:04
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,balance=0; //第n局
re:
int a=0,b=0,c=0,d=0,r,option,buyin; //r為亂數選出的馬,x為贏的馬
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)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
balance+=buyin;
goto re;
}
system("pause");
system("cls");
srand(time(NULL));
while(a!=70 && b!=70 && c!=70 && d!=70)
{
cout<<"~賽馬進行中~"<<"第"<<n<<"局"<<endl;
cout<<"|起點|--------------------------------------------------------------|終點|"<<endl;
r=rand()%4;
if(r==0)
{
a++;
}
if(r==1)
{
b++;
}
if(r==2)
{
c++;
}
if(r==3)
{
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");
}
if(a==70)
{
cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由★先馳得點!"<<endl;
}
else if(b==70)
{
cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由㊣先馳得點!"<<endl;
}
else if(c==70)
{
cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由▽先馳得點!"<<endl;
}
else
{
cout<<"~比賽結束~"<<"第"<<n<<"局"<<"由◆先馳得點!"<<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;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2