標題:
賽馬程式 (七)& 優化程式
[打印本頁]
作者:
陳品肇
時間:
2022-4-2 11:16
標題:
賽馬程式 (七)& 優化程式
本帖最後由 陳品肇 於 2022-4-2 11:45 編輯
完成選項 (3)離開 的相對應程式碼
在離開時顯示戰果, 譬如:
"沒輸沒贏! 全身而退!"
"恭喜你! 這次總共贏了100元!"
"不好意思! 讓你損失了200元!"
[attach]12939[/attach]
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
// 開局第一場
// money 拿來作為輸贏的統計
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度
string words ="賽馬進行中";
// 代表馬的名子
string name[4] = {"◆","★","▲","●"};
// 宣告一個暫存的變數
int position =0;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
// 如果買入 把錢加入餘額
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
cout<<"即將開始賽馬!"<<endl;
}else
{
cout<<"您輸入錯誤,請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
// 離開
goto end;
}
system("pause"); // 按下enter 才開始
system("cls"); // 清空畫面
srand(time(NULL)); // 撒種子亂數
// 當有任一匹跑到終點70 的時候就跳離迴圈
while(a<70 && b<70 && c<70 && d<70)
{
// 隨機挑一匹馬
r = rand()%4+1;
// 每匹馬 跑的進度
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
// 要把每匹馬的進度給輸出
// 第一匹馬
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
// 第二匹馬
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
// 第三匹馬
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
// 第四匹馬
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
//還沒有任一匹馬到終點 要清空畫面
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls"); // 清空畫面
}
}
// 如果選的馬 = 最終跑贏的結果
if(horse == winer)
{
// 現有的錢 + 投注的錢*3
blance = blance + bet*3;
// 把贏的錢做統計
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
// 把輸的錢做統計
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
// 局數+1
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次再來!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鍾易澄
時間:
2022-4-2 11:30
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
// 開局第一場
// money 拿來作為輸贏的統計
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度
// 當有任一匹跑到終點70 的時候就跳離迴圈
string words ="賽馬進行中";
// 代表馬的名子
string name[4] = {"◆","★","▲","●"};
// 宣告一個暫存的變數
int position =0;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
// 如果買入 把錢加入餘額
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
cout<<"即將開始賽馬!"<<endl;
}else
{
cout<<"您輸入錯誤,請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
// 離開
goto end;
}
system("pause"); // 按下enter 才開始
system("cls"); // 清空畫面
srand(time(NULL)); // 撒種子亂數
while(a<=70 && b<=70 && c<=70 && d<=70)
{
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
// 隨機挑一匹馬
r = rand()%4+1;
// 每匹馬 跑的進度
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
// 要把每匹馬的進度給輸出
// 第一匹馬
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
// 第二匹馬
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
// 第三匹馬
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
// 第四匹馬
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
// 當有任一個跑到71 就代表到終點 不要清空畫面
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls"); // 清空畫面
}
}
// 如果選的馬 = 最終跑贏的結果
if(horse == winer)
{
// 現有的錢 + 投注的錢*3
blance = blance + bet*3;
// 把贏的錢做統計
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
// 把輸的錢做統計
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
// 局數+1
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次再來!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
許馹東
時間:
2022-4-2 11:49
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ;
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
int position =0;
cout<<"「好事『輸』成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
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)
{
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
blance = blance - bet*2;
money = money -bet*2;
cout<<"損失"<<bet*2<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次繼續輸!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曾善勤
時間:
2022-4-2 11:53
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ;
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
int position =0;
cout<<"「好事『輸』成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
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)
{
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
blance = blance - bet*2;
money = money -bet*2;
cout<<"損失"<<bet*2<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次繼續輸!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
柳侑辰
時間:
2022-4-2 11:54
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int t=1,z=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r,tmp=0,o,buy=0,bet,horse,winer;
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
cout<<"「好事成雙」賽馬場"<<"第"<<t<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl<<endl;
cout<<"可用餘額:"<<z<<"元"<<endl<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>o;
if(o==1)
{
cout<<"買入:";
cin>>buy;
z += buy;
goto re;
}else if(o==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > z)
{
cout<<"您餘額不足,請重新下注!"<<endl;
}else if(bet >0 && bet<=z)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
z -= bet;
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)
{
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
tmp = 0;
winer = 1;
}
if(b==70)
{
tmp = 1;
winer = 2;
}
if(c==70)
{
tmp = 2;
winer = 3;
}
if(d==70)
{
tmp =3;
winer = 4;
}
words = "比賽結束!由"+name[tmp]+"先馳得點!";;
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
z = z + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
money = money + bet*3;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
money = money - bet;
}
system("pause");
t++;
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
孫子傑
時間:
2022-4-2 11:54
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
// 開局第一場
int n =1,x=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度
string words ="賽馬進行中";
// 代表馬的名子
string name[4] = {"◆","★","▲","●"};
// 宣告一個暫存的變數
int position =0;
cout<<"「智慧」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<x<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
// 如果買入 把錢加入餘額
if(option==1)
{
cout<<"買入:";
cin>>buyin;
x += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > x)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=x)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
x -= bet;
cout<<"即將開始賽馬!"<<endl;
}else
{
cout<<"您輸入錯誤,請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
// 離開
goto end;
}
system("pause"); // 按下enter 才開始
system("cls"); // 清空畫面
srand(time(NULL)); // 撒種子亂數
while(a<70 && b<70 && c<70 && d<70)
{
// 隨機挑一匹馬
r = rand()%4+1;
// 每匹馬 跑的進度
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer = 4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
// 要把每匹馬的進度給輸出
// 第一匹馬
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
// 第二匹馬
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
// 第三匹馬
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
// 第四匹馬
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
x = x +bet*3;
money = money -bet;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money ==0)
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if(money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
鍾易澄
時間:
2022-4-2 11:54
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
// 開局第一場
// money 拿來作為輸贏的統計
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度
string words ="賽馬進行中";
// 代表馬的名子
string name[4] = {"◆","★","▲","●"};
// 宣告一個暫存的變數
int position =0;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
// 如果買入 把錢加入餘額
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
cout<<"即將開始賽馬!"<<endl;
}else
{
cout<<"您輸入錯誤,請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
// 離開
goto end;
}
system("pause"); // 按下enter 才開始
system("cls"); // 清空畫面
srand(time(NULL)); // 撒種子亂數
// 當有任一匹跑到終點70 的時候就跳離迴圈
while(a<70 && b<70 && c<70 && d<70)
{
// 隨機挑一匹馬
r = rand()%4+1;
// 每匹馬 跑的進度
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
// 要把每匹馬的進度給輸出
// 第一匹馬
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
// 第二匹馬
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
// 第三匹馬
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
// 第四匹馬
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
//還沒有任一匹馬到終點 要清空畫面
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls"); // 清空畫面
}
}
// 如果選的馬 = 最終跑贏的結果
if(horse == winer)
{
// 現有的錢 + 投注的錢*3
blance = blance + bet*3;
// 把贏的錢做統計
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
// 把輸的錢做統計
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
// 局數+1
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次再來!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
徐譽豈
時間:
2022-4-2 11:56
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ;
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
int position =0;
cout<<"日本東京競馬場<東京優駿>[2400m草地] 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
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)
{
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次再來!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
許宸瑀
時間:
2022-4-2 11:56
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
int position =0;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
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)
{
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次再來!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
田家齊
時間:
2022-4-2 11:57
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n =1,blance=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ;
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
int position =0;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > blance)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=blance)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
blance -= bet;
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)
{
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer =4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
money = money + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money ==0 )
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if( money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
cout<<endl;
cout<<"謝謝光臨! 下次再來!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
郭博鈞
時間:
2022-4-2 12:03
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n=1,blance=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r,opition,buyin,bet,horse,win,money=0;
string words ="賽馬進行中";
string name[4]={"Ⅰ","Ⅱ","Ⅲ","Ⅳ"};
int position =0;
cout<<"賽馬場 第"<<n<<"局"<<endl;
cout<<"-----------------------------------------------------------------終點"<<endl;
cout<<"Ⅰ"<<endl;
cout<<"Ⅱ"<<endl;
cout<<"Ⅲ"<<endl;
cout<<"Ⅳ"<<endl;
cout<<endl;
cout<<"可用餘額"<<blance<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>opition;
if(opition==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
goto re;
}else if(opition==2)
{
cout<<"下注金額:";
cin>>bet;
}
if(bet>blance)
{
cout<<"餘額不足 請重新下注"<<endl;
system("pause");
goto re;
}else if(bet>0 && blance>=bet)
{
cout<<"請選擇 (1)Ⅰ (2)Ⅱ (3)Ⅲ (4)Ⅳ"<<endl;
cin>>horse;
blance-=bet;
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)
{
r=rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
int position;
if(a==70)
position = 0;
win=1;
if(b==70)
position =1;
win=2;
if(c==70)
position =2;
win=3;
if(d==70)
position =3;
win=4;
}
words = "比賽結束,由"+name[position]+"奪魁";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse==win)
{
blance = blance + bet*3;
money=money+bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
money=money-bet;
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money==0)
{
cout<<"沒輸沒贏"<<endl;
}else if(money>0)
{
cout<<"贏了"<<money<<"元"<<endl;
}else
{
cout<<"賠了"<<-money<<"元,下次加油"<<endl;
}
cout<<"謝謝光臨"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林鴻慶
時間:
2022-4-3 17:10
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
// 開局第一場
int n =1,x=0,money=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0,bet,horse,winer ; // 每匹馬前進的進度
string words ="賽馬進行中";
// 代表馬的名子
string name[4] = {"◆","★","▲","●"};
// 宣告一個暫存的變數
int position =0;
cout<<"「智慧」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<x<<"元"<<endl;
cout<<endl;
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
// 如果買入 把錢加入餘額
if(option==1)
{
cout<<"買入:";
cin>>buyin;
x += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>bet;
if(bet > x)
{
cout<<"您餘額不足,請重新下注!"<<endl;
system("pause");
goto re;
}else if(bet >0 && bet<=x)
{
cout<<"(1)◆ (2)★ (3)▲(4)●請選擇:";
cin>>horse;
x -= bet;
cout<<"即將開始賽馬!"<<endl;
}else
{
cout<<"您輸入錯誤,請重新下注!"<<endl;
system("pause");
goto re;
}
}else
{
// 離開
goto end;
}
system("pause"); // 按下enter 才開始
system("cls"); // 清空畫面
srand(time(NULL)); // 撒種子亂數
while(a<70 && b<70 && c<70 && d<70)
{
// 隨機挑一匹馬
r = rand()%4+1;
// 每匹馬 跑的進度
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
{
position = 0;
winer = 1;
}
if(b==70)
{
position =1;
winer = 2;
}
if(c==70)
{
position =2;
winer = 3;
}
if(d==70)
{
position =3;
winer = 4;
}
words = "比賽結束!由"+name[position]+"先馳得點!";
}
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
// 要把每匹馬的進度給輸出
// 第一匹馬
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
// 第二匹馬
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
// 第三匹馬
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
// 第四匹馬
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a<=69 && b<=69 && c<=69 && d<=69)
{
system("cls");
}
}
if(horse == winer)
{
x = x +bet*3;
money = money -bet;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
money = money -bet;
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
if(money ==0)
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if(money > 0)
{
cout<<"恭喜你! 這次總共贏了"<<money<<"元"<<endl;
}else
{
cout<<"不好意思! 讓你損失了"<<-money<<"元"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
高昀昊
時間:
2022-4-8 18:36
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n =1,blance=0,totalbuy=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0 ,pay ,choose ;
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
int position =0;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
back:
cout<<"(1)買入 (2)下注 (3)純粹觀賽 (4)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
totalbuy += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>pay;
if(pay>blance)
{
cout<<"您餘額不足,請重新下注"<<endl;
system("pause");
goto back;
}
if(pay<=0)
{
cout<<"輸入錯誤"<<endl;
goto back;
}
cout<<"(1)◆ (2)★ (3)▲ (4)● (5)離開 請選擇:";
cin>>choose;
if(choose==1)
{
}else if(choose==2)
{
}else if(choose==3)
{
}else if(choose==4)
{
}else if(choose==5)
{
goto back;
}else{
cout<<"輸入錯誤"<<endl;
goto back;
}
blance-=pay;
}else if(option==3)
{
goto play;
}else if(option==4)
{
goto end;
}else{
cout<<"輸入錯誤"<<endl;
goto back;
}
play:
system("pause");
system("cls");
srand(time(NULL));
while(a<=70 && b<=70 && c<=70 && d<=70)
{
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
if(a==70)
{
a++;
goto over;
}
if(b==70)
{
b++;
goto over;
}
if(c==70)
{
c++;
goto over;
}
if(d==70)
{
d++;
goto over;
}
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
over:
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
position = 0;
if(b==70)
position =1;
if(c==70)
position =2;
if(d==70)
position =3;
words = "比賽結束!由"+name[position]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
if(option==3)
goto keep;
if(position==0)
{
if(choose==1)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}else if(position==1)
{
if(choose==2)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}else if(position==2)
{
if(choose==3)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}else if(position==3)
{
if(choose==4)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}
}else{
system("cls");
}
}
keep:
n++;
system("pause");
goto re;
end:
if(blance==totalbuy)
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if(blance>totalbuy)
{
cout<<"恭喜你! 這次總共贏了"<<blance-totalbuy<<"元!"<<endl;
}else if(blance<totalbuy)
{
cout<<"不好意思! 讓你損失了"<<totalbuy-blance<<"元!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
高鋐鈞
時間:
2022-4-9 09:59
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int n =1,blance=0,totalbuy=0;
re:
system("cls");
int a=0,b=0,c=0,d=0,r, option, buyin =0 ,pay ,choose ;
string words ="賽馬進行中";
string name[4] = {"◆","★","▲","●"};
int position =0;
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
cout<<endl;
cout<<"可用餘額:"<<blance<<"元"<<endl;
cout<<endl;
back:
cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
cin>>option;
if(option==1)
{
cout<<"買入:";
cin>>buyin;
blance += buyin;
totalbuy += buyin;
goto re;
}else if(option==2)
{
cout<<"請下注:";
cin>>pay;
if(pay>blance)
{
cout<<"您餘額不足,請重新下注"<<endl;
system("pause");
goto back;
}
if(pay<=0)
{
cout<<"輸入錯誤"<<endl;
goto back;
}
cout<<"(1)◆ (2)★ (3)▲ (4)●請選擇:";
cin>>choose;
if(choose==1)
{
}else if(choose==2)
{
}else if(choose==3)
{
}else if(choose==4)
{
}else if(choose==5)
{
goto back;
}else{
cout<<"輸入錯誤"<<endl;
goto back;
}
blance-=pay;
}else if(option==3)
{
goto end;
}else{
cout<<"輸入錯誤"<<endl;
goto back;
}
play:
system("pause");
system("cls");
srand(time(NULL));
while(a<=70 && b<=70 && c<=70 && d<=70)
{
cout<<words<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
if(a==70)
{
a++;
goto over;
}
if(b==70)
{
b++;
goto over;
}
if(c==70)
{
c++;
goto over;
}
if(d==70)
{
d++;
goto over;
}
r = rand()%4+1;
switch(r)
{
case 1:
a++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
}
over:
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<name[0]<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<name[1]<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<name[2]<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<name[3]<<endl;
if(a==70 || b==70 || c==70 || d==70)
{
if(a==70)
position = 0;
if(b==70)
position =1;
if(c==70)
position =2;
if(d==70)
position =3;
words = "比賽結束!由"+name[position]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
if(option==3)
goto keep;
if(position==0)
{
if(choose==1)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}else if(position==1)
{
if(choose==2)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}else if(position==2)
{
if(choose==3)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}else if(position==3)
{
if(choose==4)
{
cout<<"恭喜,你賭贏了,獲得3倍的獎金"<<endl;
blance+=3*pay;
}else{
cout<<"可惜,你輸了,再接再厲"<<endl;
}
}
}else{
system("cls");
}
}
keep:
n++;
system("pause");
goto re;
end:
if(blance==totalbuy)
{
cout<<"沒輸沒贏! 全身而退!"<<endl;
}else if(blance>totalbuy)
{
cout<<"恭喜你! 這次總共贏了"<<blance-totalbuy<<"元!"<<endl;
}else if(blance<totalbuy)
{
cout<<"不好意思! 讓你損失了"<<totalbuy-blance<<"元!"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2