標題:
賽馬程式 (六)
[打印本頁]
作者:
周政輝
時間:
2018-5-19 13:54
標題:
賽馬程式 (六)
本帖最後由 周政輝 於 2018-5-19 15:19 編輯
1. 比對比賽結果與玩家下注, 判斷玩家贏了錢還是輸了錢.
2. 對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.
規則如下:
若最後勝出的選手與玩家下注相同, 玩家贏得下注金3倍的錢.
反之, 玩家損失下注金.
[attach]4129[/attach]
[attach]4130[/attach]
[attach]4131[/attach]
#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; // 判斷是哪一批馬勝利
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;
}
}
}
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)
{
point = point + (bet*3);
cout << "恭喜您獲得勝利!,目前金額如下" << endl;
cout << point << endl;
}
else
{
cout << "賭注失敗,目前金額如下" << endl;
cout << point << endl;
}
isStart = true;
}
system("pause");
return 0;
}
複製代碼
作者:
湯東緯
時間:
2018-5-19 14:54
#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;
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:
cout << "下注:";
cin >> bet;
cout<<"請下注(1)◆(2)★(3)▲(4)●"<<endl;
cin>>my_select;
if(point<=0 || point<bet)
{
cout<<"餘額不足"<<endl;
break;
}
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
isStart = false;
}
point=point-my_select ;
break;
}
}
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;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
戴嘉禾
時間:
2018-5-19 15:04
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
re:
int times=0;
times++;
while(true)
{
int horse1=0,horse2=0,horse3=0,horse4=0;
int random=0,num=0,num1=0,num2=0,num3=0,point=0;
srand (time(NULL));
system("cls");
cout<<"☆★☆[嘉禾豬]賽馬場☆★☆"<<" 第"<<times<<"場"<<endl;
cout<<"========================================================|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"☆"<<endl;
cout<<"●"<<endl;
cout<<"=============================================================="<<endl;
cout<<" ★☆★ 遊戲規則 ★☆★ "<<endl;
cout<<"1.下注正確將會獲得五倍的錢!"<<endl;
cout<<"2.下注錯誤將會失去一倍的錢!"<<endl;
cout<<"請儲值後下注 => (儲值 & 代碼 & 下注金額) (1)◆ (2)★ (3)☆ (4)●"<<endl;
cout<<"儲值幾元:";
cin>>point;
cout<<"代碼:";
cin>>num;
if(num<1||num>4)
{
cout<<"代碼錯誤!"<<endl;
system("pause");
goto re;
}
cout<<"下注金額:";
cin>>num1;
if(num1>point)
{
cout<<"儲值點數不夠!"<<endl;
goto re;
}
if(num1<100||num1>50000)
{
cout<<"金額錯誤!"<<endl;
system("pause");
goto re;
}
cout<<"是否要反悔? (1)要 (2)不要"<<endl;
cin>>num3;
if(num3==1)
{
goto re;
}
else if(num3==2)
{
goto re5;
}
re5:
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");
if(horse1==60)
{
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;
cout<<"==========================================================|===="<<endl;
cout<<"你輸入的代碼:("<<num<<")"<<endl;
cout<<"你下注了"<<num1<<"元"<<endl;
cout<<"(1)◆贏了!"<<endl;
if(num==1)
{
cout<<"恭喜你!你獲得了"<<num1*5<<"元"<<endl;
}
else if(num==2||num==3||num==4)
{
cout<<"真可惜!你失去了"<<num1<<"元"<<endl;
}
re1:
cout<<"要再玩一次嗎? (1)要 (2)不要"<<endl;
cin>>num2;
if(num2==2)
{
system("cls");
cout<<"謝謝光臨!再見!"<<endl;
}
else if(num2==1)
{
times++;
break;
}
else if(num2<1||num2>2)
{
cout<<"輸入錯誤"<<endl;
goto re1;
}
system("pause");
if(num2==1)
{
continue;
}
else
{
break;
}
}
if(horse2==60)
{
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;
cout<<"==========================================================|===="<<endl;
cout<<"你輸入的代碼:("<<num<<")"<<endl;
cout<<"你下注了"<<num1<<"元"<<endl;
cout<<"(2)★贏了!"<<endl;
if(num==2)
{
cout<<"恭喜你!你獲得了"<<num1*5<<"元"<<endl;
}
else if(num==1||num==3||num==4)
{
cout<<"真可惜!你失去了"<<num1<<"元"<<endl;
}
re2:
cout<<"要再玩一次嗎? (1)要 (2)不要"<<endl;
cin>>num2;
if(num2==2)
{
system("cls");
cout<<"謝謝光臨!再見!"<<endl;
}
else if(num2==1)
{
times++;
break;
}
else if(num2<1||num2>2)
{
cout<<"輸入錯誤"<<endl;
goto re2;
}
system("pause");
if(num2==1)
{
continue;
}
else
{
break;
}
}
if(horse3==60)
{
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;
cout<<"==========================================================|===="<<endl;
cout<<"你輸入的代碼:("<<num<<")"<<endl;
cout<<"你下注了"<<num1<<"元"<<endl;
cout<<"(3)☆贏了!"<<endl;
if(num==3)
{
cout<<"恭喜你!你獲得了"<<num1*5<<"元"<<endl;
}
else if(num==1||num==2||num==4)
{
cout<<"真可惜!你失去了"<<num1<<"元"<<endl;
}
re3:
cout<<"要再玩一次嗎? (1)要 (2)不要"<<endl;
cin>>num2;
if(num2==2)
{
system("cls");
cout<<"謝謝光臨!再見!"<<endl;
}
else if(num2==1)
{
times++;
break;
}
else if(num2<1||num2>2)
{
cout<<"輸入錯誤"<<endl;
goto re3;
}
system("pause");
if(num2==1)
{
continue;
}
else
{
break;
}
}
if(horse4==60)
{
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;
cout<<"==========================================================|===="<<endl;
cout<<"你輸入的代碼:("<<num<<")"<<endl;
cout<<"你下注了"<<num1<<"元"<<endl;
cout<<"(4)●贏了!"<<endl;
if(num==4)
{
cout<<"恭喜你!你獲得了"<<num1*5<<"元"<<endl;
}
else if(num==1||num==2||num==3)
{
cout<<"真可惜!你失去了"<<num1<<"元"<<endl;
}
re4:
cout<<"要再玩一次嗎? (1)要 (2)不要"<<endl;
cin>>num2;
if(num2==2)
{
system("cls");
cout<<"謝謝光臨!再見!"<<endl;
}
else if(num2==1)
{
times++;
break;
}
else if(num2<1||num2>2)
{
cout<<"輸入錯誤"<<endl;
goto re4;
}
system("pause");
if(num2==1)
{
continue;
}
else
{
times++;
break;
}
}
if(num2==2)
{
break;
}
}
if(num2==2)
{
break;
}
}
return 0;
}
複製代碼
作者:
林峻安
時間:
2018-5-19 15:21
#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;
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;
}
}
}
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)
{
point += win*3;
cout<<"你贏了"<<endl;
cout<<point<<endl;
}
else
{
cout<<"失敗"<<endl;
cout<<point<<endl;
}
isStart=true;
}
system("pause");
return 0;
}
複製代碼
作者:
吳秉翰
時間:
2018-5-19 15:23
本帖最後由 吳秉翰 於 2018-5-26 14:00 編輯
#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;
int my_select=0;
int win=0;
bool isStart=true;
while(true)
{
int h1=0, h2=0, h3=0, h4=0, random=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 " << "第 " <<times << "局 "<<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:
cout << "下注:";
cin >> bet;
cout<<"請下注:(1)◆(2)★(3)▲(4)●"<<endl;
cin>>my_select;
if(point<=0 || point<bet)
{
cout<<"餘額不足"<<endl;
break;
}
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
isStart = false;
}
point-=bet;
break;
}
}
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)
{
point+=bet*3;
}
isStart=true
}
system("pause");
return 0;
}
複製代碼
作者:
黃安立
時間:
2018-5-19 15:23
#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;
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:
cout << "下注:";
cin >> bet;
cout<<"請下注(1)◆(2)★(3)▲(4)●"<<endl;
cin>>my_select;
if(point<=0 || point<bet)
{
cout<<"餘額不足"<<endl;
break;
}
string error = (bet>point || bet<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
isStart = false;
}
point=point-my_select ;
break;
}
}
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;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
顏詢
時間:
2018-5-19 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;
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;
}
}
}
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;
}
else if(horse2 == 75)
{
cout<<"比賽結束,由★先馳得點"<<endl;
}
else if(horse3 == 75)
{
cout<<"比賽結束,由▲先馳得點"<<endl;
}
else if(horse4 == 75)
{
cout<<"比賽結束,由●先馳得點"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
鄭楀諺
時間:
2018-5-21 16:28
本帖最後由 鄭楀諺 於 2018-5-26 12:41 編輯
#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;
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)
{
cout<<"謝謝光臨,下次再會"<<endl;
in=false;
exit=1;
_sleep(500);
}
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;
}
else if(numh2==2)
{
cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
money=money+bet;
}
else if(numh3==2)
{
cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
money=money+bet;
}
else if(numh4==2)
{
cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
money=money+bet;
}
else
{
cout<<"唉!今天運氣不好啊!一不小心就虧了"<<bet<<"元!"<<endl;
money=money-bet;
}
}
return 0;
}
複製代碼
作者:
王駿愷
時間:
2018-5-26 13: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 paid = 0;
bool isStart= true;
int my_select = 0;
int win = 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 >> paid;
string error = (paid>point || paid<=0) ? "輸入錯誤":"";
if(error == "error")
{
break;
}
else
{
point = point - paid;
cout<<"可用餘額:"<<point<<endl;
cout << "請選擇最順眼的馬匹:" << endl;
cout << "(1)◆ (2)★ (3)▲ (4)● ";
cin >> my_select;
cout << "比賽開始!" << endl;
isStart = false;
}
break;
}
else
{
cout << "餘額不足,繼續儲值" << endl;
continue;
}
}
}
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)
{
point = point + (paid*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