標題:
賽馬程式 (五)
[打印本頁]
作者:
陳品肇
時間:
2019-4-27 13:13
標題:
賽馬程式 (五)
本帖最後由 陳品肇 於 2019-4-27 14:41 編輯
1. 完成主選單的主要架構 (運用if...else if...else判斷式)
2. 新增 (2)下注 功能
#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, bet, horse;
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>>buyin;
money+=buyin; //money=money+buyin
goto re;
}else if(option ==2)
{
cout<<"請下注: ";
cin>>bet;
if(bet > money) //下注金額大於餘額
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet>=0 && bet<= money)
{
money -= bet; // money = money - bet;
cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
cin>>horse;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"您輸入錯誤!!請重新下注!"<<endl;
system("pause");
goto re;
}
}else //離開
{
goto end;
}
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;
}
複製代碼
作者:
吳孟書
時間:
2019-4-27 14:46
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int t=1,m=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r,choose,in,bet,h;
cout<<"「好事成雙」賽馬場 第"<<t<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl<<endl;
cout<<"可用餘額:"<<m<<"元"<<endl<<endl;
w1:
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>choose;
if(choose==1)
{
cout<<"買入: ";
cin>>in;
m=m+in;
goto re;
}else if(choose==2)
{
cout<<"請下注:";
cin>>bet;
if(bet>m)
{
cout<<"您餘額不足,請重新輸入!"<<endl;
system("pause");
goto re;
}else if(bet>=0 && bet<= m)
{
m=m-bet;
cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
cin>>h;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
}else if(choose==3)
{
goto end;
}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;
end:
system("pause");
return 0;
}
複製代碼
作者:
章幼莛
時間:
2019-4-27 14:48
#include<iostream>
#include<cstdlib>
#include <time.h>
using namespace std;
int main()
{
int g=1,rest=0,bet=0;
re:
int a=0,b=0,c=0,d=0,p,option,buyin=0,horse;
system("cls");
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<<"買入金額:";
cin>>buyin;
rest+=buyin;
goto re;
}else if(option==2)
{
cout<<"下注金額: ";
cin>>bet;
if(rest<bet)
{
cout<<"餘額不足,請重新下注"<<endl;
system("pause");
goto re;
}else if(bet>=0 && rest>=bet)
{
rest-=bet;
cout<<"(1)◆ (2)★ (3)▲ (4)●請選擇:" ;
cin>>horse;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"您輸入錯誤,請重新下注"<<endl;
system("pause");
goto re;
}
}else if(option==3)
{
goto end;
}else
{
cout<<"輸入錯誤"<<endl;
system("pause");
goto re;
}
system("pause");
srand(time(NULL));
while(a!=50 && b!=50 && c!=50 && d!=50)
{
cout<<"賽馬進行中"<<endl;
cout<<"|--------------------------------------------------|"<<endl;
p = rand()%4+1;
if(p==1)
a++;
if(p==2)
b++;
if(p==3)
c++;
if(p==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;
end:
cout<<"結束"<<endl;
system("pause");
return 0;
}
複製代碼
回復
1#
陳品肇
作者:
田宇任
時間:
2019-4-27 14:48
#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,h;
system("cls");
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;
}else if(o==2)
{
cout<<"請下注: ";
cin>>z;
if(z > m)
{
cout<<"餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(z>=0 && z<= m)
{
m=m-z;
cout<<"(1)馬◆ (2)馬★ (3)馬▲ (4)馬●請選擇:";
cin>>h;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"您輸入錯誤!!請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
goto end;
}
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;
system("pause");
s++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
湯郡一
時間:
2019-4-27 14:48
#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, bet, horse;
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>>buyin;
money+=buyin;
goto re;
}else if(option ==2)
{
cout<<"請下注: ";
cin>>bet;
if(bet > money)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet>=0 && bet<= money)
{
money -= bet;
cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
cin>>horse;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"您輸入錯誤!!請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
goto end;
}
system("pause");
system("cls");
srand(time(NULL));
while(a!=75 && b!=75 && c!=75 && d!=75)
{
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==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;
}
複製代碼
作者:
洪寬瀧
時間:
2019-4-27 14:54
#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,bet,horse;
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;
}else if(j==2)
{
cout<<"請下注";
cin>>bet;
if(bet>k)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet>=0 && bet<= f)
{
f-=bet;
cout<<"(1)◆ (2)★ (3)▲(4)● 請選擇:";
cin>>horse;
cout<<"比賽即將開始"<<endl;
}else
{
cout<<"您輸入錯誤!!請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
goto end;
}
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;
end:
system("pause");
return 0;
}
複製代碼
作者:
吳孟修
時間:
2019-4-27 14:55
#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,bet,horse;
system("cls");
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"\n可用金額:"<<money<<"元\n"<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"請買入:";
cin>>buyin;
if(buyin<0)
{
cout<<"您輸入的金額有誤,請重新買入!"<<endl;
}
money+=buyin;
goto re;
}
else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet>money)
{
cout<<"您的金額不足,請重新下注!"<<endl;
system("pause");
goto re;
}
else if(bet>=0 && bet<=money)
{
money-=bet;
cout<<"(1)◆ (2)★ (3)▲ (4)● 請選擇:";
cin>>horse;
cout<<"比賽即將開始!\n\n";
}
else
{
cout<<"您輸入的金額有誤,請重新下注!"<<endl;
system("pause");
goto re;
}
}
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<<"比賽結束!由";
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;
end:
system("pause");
return 0;
}
複製代碼
作者:
曲書辰
時間:
2019-4-27 14:56
#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-4-27 15:14
#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<<"由◆拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<endl;
}
}
else if(b==50)
{cout<<"由★拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<endl;
}
}
else if(c==50)
{cout<<"由▲拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<endl;
}
}
else
{cout<<"由●拿下勝利";
if(peo==a)
{
cout<<"贏得"<<out*3<<endl;
mon+=out*3;
}else
{cout<<"損失"<<out<<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 15:14
本帖最後由 王瑞喻 於 2019-5-9 23:47 編輯
#include<iostream>
#include<cstdlib>
#include<time>
using namespace std;
int main()
{
int n=1,money=0; //第n局
re:
int a=0,b=0,c=0,d=0,r,option,buyin,bet,horse; //r為亂數選出的馬,x為贏的馬
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>>buyin;
balance+=buyin; //money=money+buyin
goto re;
}else if(option==2)
{
cout<<"請下注: ";
cin>>bet;
if(bet>money)//下注金額大於餘額
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet>=0 && bet<=money)
{
money-=bet;//money=money-bet
cout<<"(1)★(2)㊣(3)▽(4)◆ 請選擇:";
cin>>horse;
cout<<"比賽即將開始!"<<endl<<endl;
}else
{
cout<<"您輸入錯誤!請重新下注!"<<endl;
system("pause");
goro re;
}
}else //離開
{
goto end;
}
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;
end;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2