註冊
登錄
論壇
搜索
幫助
導航
私人消息 (0)
公共消息 (0)
系統消息 (0)
好友消息 (0)
帖子消息 (0)
種子論壇 | 高雄市資訊培育協會學員討論區
»
結訓課程 (青少年程式設計班)
»
C++程式設計入門(201302)
» 賽馬程式 (八)
返回列表
發帖
發短消息
加為好友
tonyh
當前離線
UID
94
帖子
7139
精華
21
積分
210
閱讀權限
150
在線時間
2626 小時
註冊時間
2011-1-8
最後登錄
2025-3-13
超級版主
1
#
跳轉到
»
倒序看帖
打印
字體大小:
t
T
tonyh
發表於 2013-11-30 14:31
|
顯示全部帖子
賽馬程式 (八)
本帖最後由 tonyh 於 2013-11-30 14:56 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int balance=0,n=1,money=0;
int option,buyin,bet,winner;
re1:
int a=0,b=0,c=0,d=0,r;
system("cls");
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"-------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
re2:
cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
cin>>option;
if(option==1)
{
cout<<"買入: ";
cin>>buyin;
balance+=buyin;
goto re1;
}else if(option==2)
{
if(balance==0)
{
cout<<"可用餘額不足! 請先買入!"<<endl<<endl;
system("pause");
goto re1;
}
cout<<"下注: ";
cin>>bet;
if(bet>balance)
{
cout<<"可用餘額不足! 請先買入!"<<endl<<endl;
system("pause");
goto re1;
}else
{
cout<<endl<<"(1)◆ (2)★ (3)▲ (4)● 請選擇: ";
cin>>option;
cout<<"比賽即將開始!"<<endl<<endl;
system("pause");
}
}else if(option==3)
{
goto end;
}else
{
cout<<"輸入錯誤!"<<endl<<endl;
system("pause");
goto re1;
}
srand(time(NULL));
while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
{
r=rand()%4;
if(r==0)
a++;
else if(r==1)
b++;
else if(r==2)
c++;
else
d++;
cout<<"比賽進行中";
cout<<endl<<"-------------------------------------------------------------------| 終點"<<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");
}
if(a>b && a>c && a>d)
{
cout<<"◆ 勝出!";
winner=1;
}else if(b>a && b>c && b>d)
{
cout<<"★ 勝出!";
winner=2;
}else if(c>a && c>b && c>d)
{
cout<<"▲ 勝出!";
winner=3;
}else
{
cout<<"● 勝出!";
winner=4;
}
cout<<endl<<"-------------------------------------------------------------------| 終點"<<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;
if(option==winner)
{
cout<<endl<<"贏了 "<<bet*3<<"元!"<<endl;
balance+=bet*3;
money+=bet*3;
}else
{
cout<<endl<<"損失 "<<bet<<"元!"<<endl;
balance-=bet;
money-=bet;
}
cout<<endl;
n++;
system("pause");
goto re1;
end:
if(money==0)
cout<<endl<<"沒輸沒贏! 全身而退!"<<endl;
if(money>0)
cout<<endl<<"恭喜你! 這次總共贏了"<<money<<"元!"<<endl;
if(money<0)
cout<<endl<<"不好意思! 讓你損失了"<<-money<<"元!"<<endl;
cout<<endl<<"謝謝光臨! 下次再來!"<<endl<<endl;
system("pause");
return 0;
}
複製代碼
收藏
分享
返回列表
谷哥人營隊
Python研習營(113-114)
114年Python證照特訓
114年谷哥人程式體驗營
114年APCS冬令營
113Scratch夏令營
Scratch冬令營(113-114)
113年國三專班
Python證照特訓營(113)
113年程式夏令營(一)(二)
113年APCS夏令營(一)(二)
C語言 / C++ (特別輔導)
C++證照
C#
家教特輔
C語言特輔/證照(家教)
C++證照
C#
HTML5+CSS+JavaScript+PHP+MySQL
Java 家教 (王捷恩)
113新版塊名稱
快樂學 Scratch
Python 家教 (王捷恩 康恒睿)
Python 特別輔導 (家教)
快樂 C++ (家教)
iKnow
我愛 Java (家教)
程式解題我最行 (家教)
程式常態班
C++ 新生挑戰區
考照心得分享
快樂 C++11307週五19:00
快樂C++11309週六13:30-15:30
快樂 C++11403週六1000
快樂 C++11303 (週六15:40-17:40) 3F
程式解題我最行 (週六15:30-17:30) 3F
快樂 C++ (週六13:30-15:30) 3F
快樂 C++ (週六19:00-21:00) 3F
程式解題我最行 (週六10:00-12:00) 3F
快樂學 Scratch
程式解題我最行(週五19:00-21:00)
快樂 C++ (週六13:30-15:30) 3F
程式解題我最行(週三19:15-21:15)
快樂 C++11207週六10
快樂 C++11208週六19:00
程式解題我最行 (週六19:00-21:00) 3F
程式解題我最行 (週四19:10-21:10)
產投職訓
結訓課程 (產投職訓)
Php & MySQL old
Illustrator old
Dreamweaver old
Android手機程式開發班
PHP & MySQL電子商務互動式網站實作班 (102下)
PHP & MySQL (102上)
PHP & MySQL電子商務互動式網站實作班
Photoshop數位影像設計初階
Flash創意廣告動畫初階
行銷短片視訊剪輯
數位商業攝影實務班
PHP & MySQL電子商務系統開發實務初階班
電子商務系統開發實務中階班
Server基礎架設&動態網頁設計初階班
Java視窗應用程式設計與遊戲開發班
Illustrator時尚插畫創作設計初階班
102上Php & MySQL 初階班
電子商務互動式網站實作中階
Dreamweaver多媒體網頁設計
Android手機程式開發班(2012年10月)
PHP & MySQL (2012年10月)
創意塗鴉
yahoo橫幅
google橫幅
市民學苑
第二屆樂活部落格
第一屆電腦設備簡易維護和故障排除班
專案訓練
電子商務創業班
TQC PHP認證
投資理財班
領隊導遊班
電腦基礎及網路應用身心障礙專班
應用軟體網頁化開發
[收藏此主題]
[關注此主題的新回復]
[通過 QQ、MSN 分享給朋友]