標題:
[隨堂測驗] 賽馬程式 (三)
[打印本頁]
作者:
方浩葦
時間:
2024-7-27 11:15
標題:
[隨堂測驗] 賽馬程式 (三)
1. 在比賽首頁顯示第幾局
2. 在比賽結束頁顯示哪一位選手勝出
本帖隱藏的內容需要回復才可以瀏覽
作者:
林少謙
時間:
2024-7-27 15:08
本帖最後由 林少謙 於 2024-7-27 16:09 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int x,y,t=1;
re2:
int a[]{0,0,0,0};
string b[]{"◆","★","▲","●"};
cout<<"空蕩蕩賽馬場 第"<<t<<"場"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
re:
if(a[0]<73&&a[1]<73&&a[2]<73&&a[3]<73)
{
system("cls");
cout<<"比賽開始"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=3; i++)
{
x=rand()%5+1;
a[i]+=x;
}
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
_sleep(100);
goto re;
}
else
{
if(a[0]>=73)
y=0;
if(a[1]>=73)
y=1;
if(a[2]>=73)
y=2;
if(a[3]>=73)
y=3;
system("cls");
cout<<"比賽結束由"<<b[y]<<"獲勝"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
}
system("pause");
t+=1;
goto re2:
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-7-27 16:10
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int s=1;
re1:
srand(time(NULL));
cout<<"賽馬場 第"<<s<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
int a[]{0,0,0,0};
int t;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
cout<<"比賽開始"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
re:
if(a[0]<73&&a[1]<73&&a[2]<73&&a[3]<73){
system("cls");
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
s=rand()%4;
a[s]++;
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
_sleep(1);
goto re;
}else{
system("cls");
if(a[0]>=73){
cout<<"比賽結束,最終由◆勝出!!!"<<endl;
}else if(a[1]>=73){
cout<<"比賽結束,最終由★勝出!!!"<<endl;
}else if(a[2]>=73){
cout<<"比賽結束,最終由▲勝出!!!"<<endl;
}else if(a[3]>=73){
cout<<"比賽結束,最終由●勝出!!!"<<endl;
}
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
}
for(int i=1; i<=a[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=a[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=a[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=a[3]; i++)
cout<<" ";
cout<<"●"<<endl;
s++;
system("pause");
goto re1;
return 0;
}
複製代碼
作者:
李唯銘
時間:
2024-7-27 16:17
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
n=1;
re:
system("cls");
int a=0, b=0, c=0, d=0;
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true){
system("cls");
cout<<"比賽中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;\
int r=rand()%4;
if(r==0){
a++;
}
else if(r==1){
b++;
}
else if(r==2){
c++;
}
else if(r==3){
d++;
}
for(int i=1; i<=a; i++){
cout<<" ";}
cout<<"◆"<<endl;
for(int j=1; j<=b; j++){
cout<<" ";}
cout<<"★"<<endl;
for(int k=1; k<=c; k++){
cout<<" ";}
cout<<"▲"<<endl;
for(int l=1; l<=d; l++){
cout<<" ";}
cout<<"●"<<endl;
_sleep(50);
if((a==73)||(b==73)||(c==73)||(d==73))
break;
}
system("cls");
if(a==73){
cout<<"比賽結束,由◆先馳得點"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
}
if(b==73){
cout<<"比賽結束,由★先馳得點"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
}
if(c==73){
cout<<"比賽結束,由▲先馳得點"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
}
if(d==73){
cout<<"比賽結束,由●先馳得點"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
}
for(int i=1; i<=a; i++){
cout<<" ";}
cout<<"◆"<<endl;
for(int j=1; j<=b; j++){
cout<<" ";}
cout<<"★"<<endl;
for(int k=1; k<=c; k++){
cout<<" ";}
cout<<"▲"<<endl;
for(int l=1; l<=d; l++){
cout<<" ";}
cout<<"●"<<endl;
n++;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-27 16:24
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
int z=1;
int x,y;
re1:
int n[]={0,0,0,0};
system("cls");
srand(time(NULL));
cout<<"「好事成雙」賽馬程式"<<endl;
cout<<"---------------------------------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
re:
if(n[0]<70&&n[1]<70&&n[2]<70&&n[3]<73){
system("cls");
cout<<"比賽進行中 第"<<z<<"局"<<endl;
cout<<"-------------------------------------------------------------------|終點"<<endl;
int speed=0.01;
x=rand()%4;
n[x]++;
for(int i=1;i<=n[0];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1;i<=n[1];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1;i<=n[2];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1;i<=n[3];i++)
cout<<" ";
cout<<"●"<<endl;
_sleep(speed);
goto re;
}
else{
system("cls");
if(n[0]>=70)
cout<<"由◆勝出,";
else if(n[1]>=70)
cout<<"由★勝出,";
else if(n[2]>=70)
cout<<"由▲勝出,";
else if(n[3]>=70)
cout<<"由●勝出,";
cout<<"比賽結束!"<<endl;
cout<<"-------------------------------------------------------------------|終點"<<endl;
for(int i=1;i<=n[0];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1;i<=n[1];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1;i<=n[2];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1;i<=n[3];i++)
cout<<" ";
cout<<"●"<<endl;
}
z++;
system("pause");
goto re1;
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-7-27 16:30
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
system("cls");
int n=1;
int s[]={0,0,0,0};
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
if(s[r]==73)
break;
_sleep(0.00000001);
}
system("cls");
cout<<"比賽結束 ";
if(s[0]==73)
cout<<"由◆先馳得點"<<endl;
if(s[1]==73)
cout<<"由★先馳得點"<<endl;
if(s[2]==73)
cout<<"由▲先馳得點"<<endl;
if(s[3]==73)
cout<<"由●先馳得點"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
n++;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
李偈睿
時間:
2024-8-10 15:31
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
re:
system("cls");
int n=1;
int s[]={0,0,0,0};
srand(time(NULL));
cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
system("cls");
int r=rand()%4;
s[r]++;
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
if(s[r]==73)
break;
_sleep(0.00000001);
}
system("cls");
cout<<"比賽結束 ";
if(s[0]==73)
cout<<"由◆先馳得點"<<endl;
if(s[1]==73)
cout<<"由★先馳得點"<<endl;
if(s[2]==73)
cout<<"由▲先馳得點"<<endl;
if(s[3]==73)
cout<<"由●先馳得點"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=s[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0; i<=s[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0; i<=s[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0; i<=s[3]; i++)
cout<<" ";
cout<<"●"<<endl;
n++;
system("pause");
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2