標題:
賽馬程式 (七)
[打印本頁]
作者:
周政輝
時間:
2018-5-26 13:47
標題:
賽馬程式 (七)
本帖最後由 周政輝 於 2018-5-26 14:33 編輯
完成選項 (3)離開 的相對應程式碼
在離開時顯示戰果, 譬如:
"沒輸沒贏! 全身而退!"
"恭喜你! 這次總共贏了100元!"
"不好意思! 讓你損失了200元!"
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int times=1;
int point = 0;
int select = 0;
int buy = 0;
int bet = 0;
bool isStart= true;
int my_select = 0;
int win = 0; // 判斷是哪一批馬勝利
int result =0;
int buy_total =0;
while(true)
{
int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<< "可用帳戶餘額:" << point << endl;
while(isStart)
{
cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
cin >> select;
switch(select)
{
case 1:
cout << "買入:";
cin >> buy;
// 三元運算子
point += (buy<=0) ? point : buy;
cout<< "可用帳戶餘額:" << point << endl;
break;
case 2:
if(point >=0)
{
cout << "下注:";
cin >> bet;
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
buy_total += bet;
point = point - bet;
cout<< "可用帳戶餘額:" << point << endl;
cout << "請選擇以下的馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> my_select;
cout << "比賽正式開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足,請先進行儲值" << endl;
continue;
}
case 3:
if(result > buy_total)
{
cout << "恭喜你! 這次總共贏了" << result - buy_total << "元!" << endl;
}
else if (result == buy_total)
{
cout << "沒輸沒贏! 全身而退!";
}
else if(result <buy_total)
{
cout << "不好意思! 讓你損失了" << buy_total - result << "元!" << endl;
}
system("pause");
return 0;
}
}
system("pause");
system("cls");
while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
{
random=rand()%4; //產生0~3之隨機亂數
if(random==0) {
horse1++;
}
else if(random==1) {
horse2++;
}
else if(random==2) {
horse3++;
}
else if(random==3) {
horse4++;
}
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=horse1; i++) {
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1; i<=horse2; i++) {
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1; i<=horse3; i++) {
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1; i<=horse4; i++) {
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
times++;
system("cls");
if(horse1 == 75)
{
cout<<"比賽結束,由◆先馳得點"<<endl;
win = 1;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
win = 2;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
win = 3;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
win = 4;
}
if(my_select == win)
{
result += (bet*3);
point = point + (bet*3) ;
cout << "恭喜您獲得勝利!,目前金額如下" << endl;
cout << point << endl;
}
else
{
cout << "賭注失敗,目前金額如下" << endl;
cout << point << endl;
}
isStart = true;
}
system("pause");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-5-26 14:06
本帖最後由 鄭楀諺 於 2018-5-26 14:11 編輯
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int random=0,round=1;
int money=0,ans=0,bet=0,newmoney=0,exit=0,got=0,loose=0;
srand(time(NULL));
while(true)
{
bool in=true;
int numh=0,numh1=0,numh2=0,numh3=0,numh4=0;
int h1=0,h2=0,h3=0,h4=0;
while(in)
{
cout<<"第"<<round<<"局"<<endl;
cout<<"「好事成雙」賽馬場"<<endl;
cout<<"|-------------------------------------------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<"可用餘額"<<money<<"元"<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>ans;
if(ans==1)
{
cout<<"買入:";
cin>>newmoney;
if(newmoney<=0)
{
cout<<"輸入錯誤!"<<endl;
_sleep(500);
}
else
{
money=money+newmoney;
}
}
if(ans==2)
{
cout<<"下注:";
cin>>bet;
if(bet<=0)
{
cout<<"輸入錯誤!";
_sleep(500);
}
if(bet>money)
{
cout<<"餘額不足!";
_sleep(500);
}
else
{
in=false;
cout<<"(1) ◆"<<endl;
cout<<"(2) ★"<<endl;
cout<<"(3) ▲"<<endl;
cout<<"(4) ●"<<endl;
cout<<"請輸入下注馬匹代碼:"<<endl;
cin>>numh;
if(numh==1)
{
numh1++;
}
if(numh==2)
{
numh2++;
}
if(numh==3)
{
numh3++;
}
if(numh==4)
{
numh4++;
}
if(numh>4)
{
cout<<"餘額不足!";
_sleep(500);
}
}
}
if(ans==3)
{
if(loose>got)
{
cout<<"不好意思! 讓你損失了"<<loose<<"元!"<<endl;
}
if(loose<got)
{
cout<<"恭喜你! 這次總共贏了"<<got<<"元!"<<endl;
}
if(loose==got)
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}
cout<<"謝謝光臨,下次再會"<<endl;
in=false;
exit=1;
_sleep(5000);
}
if(ans>3)
{
cout<<"輸入錯誤!";
_sleep(500);
}
system("cls");
}
if(exit!=0)
{
break;
}
while(h1!=75&&h2!=75&&h3!=75&&h4!=75)
{
random=rand()%4;
if(random==0)
{
h1++;
}
if(random==1)
{
h2++;
}
if(random==2)
{
h3++;
}
if(random==3)
{
h4++;
}
cout<<"比賽進行中"<<endl;
cout<<"|-------------------------------------------------------------------------|終點"<<endl;
for(int i=0;i<=h1;i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=h2;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=h3;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=h4;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
round++;
system("cls");
cout<<"比賽結束! 由";
if(h1==75)
{
cout<<"◆搶先得馳"<<endl;
numh1++;
}
if(h2==75)
{
cout<<"★搶先得馳"<<endl;
numh2++;
}
if(h3==75)
{
cout<<"▲搶先得馳"<<endl;
numh3++;
}
if(h4==75)
{
cout<<"●搶先得馳"<<endl;
numh4++;
}
if(numh1==2)
{
cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
money=money+bet;
got=bet+got;
}
else if(numh2==2)
{
cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
money=money+bet;
got=bet+got;
}
else if(numh3==2)
{
cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
money=money+bet;
got=bet+got;
}
else if(numh4==2)
{
cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
money=money+bet;
got=bet+got;
}
else
{
cout<<"唉!今天運氣不好啊!一不小心就虧了"<<bet<<"元!"<<endl;
money=money-bet;
loose=bet+loose;
}
}
return 0;
}
複製代碼
作者:
戴嘉禾
時間:
2018-5-26 14:39
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int times=1;
int point=0;
int select=0;
int buy=0;
int bet=0;
bool isStart=true;
int myselect=0;
int win=0; // 判斷是哪一批馬勝利
int result=0;
int all=0;
while(true)
{
int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<< "可用帳戶餘額:" << point << endl;
while(isStart)
{
cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
cin >> select;
switch(select)
{
case 1:
cout << "買入:";
cin >> buy;
// 三元運算子
point += (buy<=0) ? point : buy;
cout<< "可用帳戶餘額:" << point << endl;
break;
case 2:
if(point >=0)
{
cout << "下注:";
cin >> bet;
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
all += bet;
point = point - bet;
cout<< "可用帳戶餘額:" << point << endl;
cout << "請選擇以下的馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> myselect;
cout << "比賽正式開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足,請先進行儲值" << endl;
continue;
}
case 3:
if(result > all)
{
cout << "恭喜你! 這次總共贏了" << result - all << "元!" << endl;
}
else if (result == all)
{
cout << "沒輸沒贏! 全身而退!"<<endl;
}
else if(result <all)
{
cout << "不好意思! 讓你損失了" << all - result << "元!" << endl;
}
system("pause");
return 0;
}
}
system("pause");
system("cls");
while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
{
random=rand()%4; //產生0~3之隨機亂數
if(random==0) {
horse1++;
}
else if(random==1) {
horse2++;
}
else if(random==2) {
horse3++;
}
else if(random==3) {
horse4++;
}
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=horse1; i++) {
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1; i<=horse2; i++) {
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1; i<=horse3; i++) {
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1; i<=horse4; i++) {
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
times++;
system("cls");
if(horse1 == 75)
{
cout<<"比賽結束,由◆先馳得點"<<endl;
win = 1;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
win = 2;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
win = 3;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
win = 4;
}
if(myselect == win)
{
result += (bet*3);
point = point + (bet*3) ;
cout << "恭喜您獲得勝利!,目前金額如下" << endl;
cout << point << endl;
}
else
{
cout << "賭注失敗,目前金額如下" << endl;
cout << point << endl;
}
isStart = true;
}
system("pause");
return 0;
}
複製代碼
作者:
林峻安
時間:
2018-5-26 14:47
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int times=1;
int point = 0;
int select = 0;
int buy = 0;
int bet = 0;
bool isStart= true;
int my_select = 0;
int win=0;
int loose=0;
int buy_toto=0;
while(true)
{
int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<< "可用帳戶餘額:" << point << endl;
while(isStart)
{
cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
cin >> select;
switch(select)
{
case 1:
cout << "買入:";
cin >> buy;
point += (buy<=0) ? point : buy;
cout<< "可用帳戶餘額:" << point << endl;
break;
case 2:
if(point >=0)
{
cout << "下注:";
cin >> bet;
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
point = point - bet;
cout<< "可用帳戶餘額:" << point << endl;
cout << "請選擇以下的馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> my_select;
cout << "比賽正式開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足,請先進行儲值" << endl;
continue;
}
case 3:
if(buy_toto<loose)
{
cout<<"恭喜你! 這次總共贏了"<<buy_toto-loose<<"元"<<endl;
}
else if(buy_toto==loose)
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}
else if(loose>buy_toto)
{
cout<<"不好意思! 讓你損失了"<<buy_toto-loose<<"元"<<endl;
}
}
}
system("pause");
system("cls");
while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
{
random=rand()%4;
if(random==0) {
horse1++;
}
else if(random==1) {
horse2++;
}
else if(random==2) {
horse3++;
}
else if(random==3) {
horse4++;
}
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=horse1; i++) {
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1; i<=horse2; i++) {
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1; i<=horse3; i++) {
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1; i<=horse4; i++) {
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
times++;
system("cls");
if(horse1 == 75)
{
cout<<"比賽結束,由◆先馳得點"<<endl;
win=1;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
win=2;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
win=3;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
win=4;
}
if(my_select==win)
{
loose += (win*3);
point += loose+(win*3);
cout<<"你贏了"<<endl;
cout<<point<<endl;
}
else
{
cout<<"失敗"<<endl;
cout<<point<<endl;
}
isStart=true;
}
system("pause");
return 0;
}
複製代碼
作者:
王駿愷
時間:
2018-5-26 14:47
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int times=1;
int point = 0;
int select = 0;
int buy = 0;
int pay = 0;
bool isStart= true;
int my_select = 0;
int win = 0;
int result =0;
int buy_total =0;
while(true)
{
int h1=0, h2=0, h3=0, h4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<< "可用帳戶餘額:" << point << endl;
while(isStart)
{
cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
cin >> select;
switch(select)
{
case 1:
cout << "買入:";
cin >> buy;
point += (buy<=0) ? point : buy;
cout<< "可用帳戶餘額:" << point << endl;
break;
case 2:
if(point >=0)
{
cout << "下注:";
cin >> pay;
string error = (pay>point || pay<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
buy_total += pay;
point = point - pay;
cout<< "帳戶餘額:" << point << endl;
cout << "請選擇馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> my_select;
cout << "比賽開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足繼續儲值" << endl;
continue;
}
case 3:
if(result > buy_total)
{
cout << "共贏了" << result - buy_total << "元" << endl;
}
else if (result == buy_total)
{
cout << "沒輸沒贏全輸而退";
}
else if(result <buy_total)
{
cout << "賠" << buy_total - result << "元" << endl;
}
system("pause");
return 0;
}
}
system("pause");
system("cls");
while(h1!=75 && h2!=75 && h3!=75 && h4!=75)
{
random=rand()%4;
if(random==0)
{
h1++;
}
else if(random==1)
{
h2++;
}
else if(random==2)
{
h3++;
}
else if(random==3)
{
h4++;
}
cout<<"比賽中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=h1; i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1; i<=h2; i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1; i<=h3; i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1; i<=h4; i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
times++;
system("cls");
if(h1 == 75)
{
cout<<"比賽結束,由◆先馳得點"<<endl;
win = 1;
}
else if(h2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
win = 2;
}
else if(h3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
win = 3;
}
else if(h4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
win = 4;
}
if(my_select == win)
{
result += (pay*3);
point = point + (pay*3) ;
cout << "目前金額如下" << endl;
cout << point << endl;
}
else
{
cout << "賭注失敗,目前金額如下" << endl;
cout << point << endl;
}
isStart = true;
}
system("pause");
return 0;
}
複製代碼
作者:
黃安立
時間:
2018-5-26 14:53
z
複製代碼
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int times=1;
int point = 0;
int select = 0;
int buy = 0;
int pay = 0;
bool isStart= true;
int my_select = 0;
int win = 0;
int result =0;
int buy_total =0;
while(true)
{
int h1=0, h2=0, h3=0, h4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<< "可用帳戶餘額:" << point << endl;
while(isStart)
{
cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
cin >> select;
switch(select)
{
case 1:
cout << "買入:";
cin >> buy;
point += (buy<=0) ? point : buy;
cout<< "可用帳戶餘額:" << point << endl;
break;
case 2:
if(point >=0)
{
cout << "下注:";
cin >> pay;
string error = (pay>point || pay<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
buy_total += pay;
point = point - pay;
cout<< "帳戶餘額:" << point << endl;
cout << "請選擇馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> my_select;
cout << "比賽開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足繼續儲值" << endl;
continue;
}
case 3:
if(result > buy_total)
{
cout << "共贏了" << result - buy_total << "元" << endl;
}
else if (result == buy_total)
{
cout << "沒輸沒贏全輸而退";
}
else if(result <buy_total)
{
cout << "賠" << buy_total - result << "元" << endl;
}
system("pause");
return 0;
}
}
system("pause");
system("cls");
while(h1!=75 && h2!=75 && h3!=75 && h4!=75)
{
random=rand()%4;
if(random==0)
{
h1++;
}
else if(random==1)
{
h2++;
}
else if(random==2)
{
h3++;
}
else if(random==3)
{
h4++;
}
cout<<"比賽中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=h1; i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1; i<=h2; i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1; i<=h3; i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1; i<=h4; i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
times++;
system("cls");
if(h1 == 75)
{
cout<<"比賽結束,由◆先馳得點"<<endl;
win = 1;
}
else if(h2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
win = 2;
}
else if(h3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
win = 3;
}
else if(h4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
win = 4;
}
if(my_select == win)
{
result += (pay*3);
point = point + (pay*3) ;
cout << "目前金額如下" << endl;
cout << point << endl;
}
else
{
cout << "賭注失敗,目前金額如下" << endl;
cout << point << endl;
}
isStart = true;
}
system("pause");
return 0;
}
複製代碼
作者:
顏詢
時間:
2018-5-26 15:02
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int times=1;
int point = 0;
int select = 0;
int buy = 0;
int bet = 0;
bool isStart= true;
int my_select = 0;
int win = 0;
int result =0;
int buy_total =0;
while(true)
{
int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<< "可用帳戶餘額:" << point << endl;
while(isStart)
{
cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
cin >> select;
switch(select)
{
case 1:
cout << "買入:";
cin >> buy;
point += (buy<=0) ? point : buy;
cout<< "可用帳戶餘額:" << point << endl;
break;
case 2:
if(point >=0)
{
cout << "下注:";
cin >> bet;
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
buy_total += bet;
point = point - bet;
cout<< "可用帳戶餘額:" << point << endl;
cout << "請選擇以下的馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> my_select;
cout << "比賽正式開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足,請先進行儲值" << endl;
continue;
}
case 3:
if(result > buy_total)
{
cout << "恭喜你! 這次總共贏了" << result - buy_total << "元!" << endl;
}
else if (result == buy_total)
{
cout << "沒輸沒贏! 全身而退!";
}
else if(result <buy_total)
{
cout << "不好意思! 讓你損失了" << buy_total - result << "元!" << endl;
}
system("pause");
return 0;
}
}
system("pause");
system("cls");
while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
{
random=rand()%4;
if(random==0) {
horse1++;
}
else if(random==1) {
horse2++;
}
else if(random==2) {
horse3++;
}
else if(random==3) {
horse4++;
}
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=horse1; i++) {
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1; i<=horse2; i++) {
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1; i<=horse3; i++) {
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1; i<=horse4; i++) {
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
times++;
system("cls");
if(horse1 == 75)
{
cout<<"比賽結束,由◆先馳得點"<<endl;
win = 1;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
win = 2;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
win = 3;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
win = 4;
}
if(my_select == win)
{
result += (bet*3);
point = point + (bet*3) ;
cout << "恭喜您獲得勝利!,目前金額如下" << endl;
cout << point << endl;
}
else
{
cout << "賭注失敗,目前金額如下" << endl;
cout << point << endl;
}
isStart = true;
}
system("pause");
return 0;
}
複製代碼
作者:
湯東緯
時間:
2018-5-26 15:25
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int times=1;
int point = 0;
int select = 0;
int buy = 0;
int bet = 0;
bool isStart= true;
int my_select = 0;
int win = 0;
int result =0;
int buy_total =0;
while(true)
{
int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<< "可用帳戶餘額:" << point << endl;
while(isStart)
{
cout<< "(1)儲值 (2) 下注 (3)離開 請選擇:";
cin >> select;
switch(select)
{
case 1:
cout << "買入:";
cin >> buy;
point += (buy<=0) ? point : buy;
cout<< "可用帳戶餘額:" << point << endl;
break;
case 2:
if(point >=0)
{
cout << "下注:";
cin >> bet;
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
buy_total += bet;
point = point - bet;
cout<< "可用帳戶餘額:" << point << endl;
cout << "請選擇以下的馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> my_select;
cout << "比賽正式開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足,請先進行儲值" << endl;
continue;
}
case 3:
if(result > buy_total)
{
cout << "恭喜你! 這次總共贏了" << result - buy_total << "元!" << endl;
}
else if (result == buy_total)
{
cout << "沒輸沒贏! 全身而退!";
}
else if(result <buy_total)
{
cout << "不好意思! 讓你損失了" << buy_total - result << "元!" << endl;
}
system("pause");
return 0;
}
}
system("pause");
system("cls");
while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
{
random=rand()%4;
if(random==0) {
horse1++;
}
else if(random==1) {
horse2++;
}
else if(random==2) {
horse3++;
}
else if(random==3) {
horse4++;
}
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=horse1; i++) {
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1; i<=horse2; i++) {
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1; i<=horse3; i++) {
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1; i<=horse4; i++) {
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
times++;
system("cls");
if(horse1 == 75)
{
cout<<"比賽結束,由◆先馳得點"<<endl;
win = 1;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
win = 2;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
win = 3;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
win = 4;
}
if(my_select == win)
{
result += (bet*3);
point = point + (bet*3) ;
cout << "恭喜您獲得勝利!,目前金額如下" << endl;
cout << point << endl;
}
else
{
cout << "賭注失敗,目前金額如下" << endl;
cout << point << endl;
}
isStart = true;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2