標題:
賽馬程式(六)
[打印本頁]
作者:
陳品肇
時間:
2022-4-2 10:22
標題:
賽馬程式(六)
本帖最後由 陳品肇 於 2022-4-2 10:39 編輯
1. 比對比賽結果與玩家下注, 判斷玩家贏了錢還是輸了錢.
2. 對變數balance做加減, 使可用餘額會隨著玩家輸贏而增減.
規則如下:
若最後勝出的選手與玩家下注相同, 玩家贏得下注金3倍的錢.
反之, 玩家損失下注金.
[attach]12936[/attach]
[attach]12938[/attach]
[attach]12937[/attach]
#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, 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;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
// 局數+1
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
高鋐鈞
時間:
2022-4-2 11:02
#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, 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)
{
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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
曾善勤
時間:
2022-4-2 11:06
#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, 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)
{
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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
許宸瑀
時間:
2022-4-2 11:07
#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, 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)
{
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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
孫子傑
時間:
2022-4-2 11:07
#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, 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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
許馹東
時間:
2022-4-2 11:09
#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, 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)
{
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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
柳侑辰
時間:
2022-4-2 11:11
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int t=1,z=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)
{
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++;
}
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;
tmp = b==70 ? 1 :0;
tmp = c==70 ? 2 :0;
tmp = d==70 ? 3 :0;
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]+"先馳得點!";;
}
if(a==71 || b==71 || c==71 || d==71)
{
}else
{
system("cls");
}
}
if(horse == winer)
{
z = z + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
system("pause");
t++;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
高昀昊
時間:
2022-4-2 11:13
#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, 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;
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:
return 0;
}
複製代碼
作者:
徐譽豈
時間:
2022-4-2 11:13
本帖最後由 徐譽豈 於 2022-4-2 11:32 編輯
#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, 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)
{
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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
田家齊
時間:
2022-4-2 11:14
#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, 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)
{
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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
鍾易澄
時間:
2022-4-2 11:14
#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, 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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
林鴻慶
時間:
2022-4-2 11:27
#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, 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)
{
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]+"先馳得點!";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse == winer)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
郭博鈞
時間:
2022-4-2 11:27
#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;
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)
{
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)
{
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]+"奪魁";
}
if(a==71 || b==71 || c==71 || d==71)
{
}else{
system("cls");
}
}
if(horse==win)
{
blance = blance + bet*3;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
林紘憲
時間:
2022-4-2 11:55
#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, 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;
cout<<"您贏了"<<bet*3<<"元"<<endl;
}else
{
cout<<"損失"<<bet<<"元"<<endl;
}
// 局數+1
n++;
system("pause");
goto re;
end:
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2