標題:
[隨堂測驗] 賽馬程式 (四)
[打印本頁]
作者:
王瑞喻
時間:
2019-12-9 17:06
標題:
[隨堂測驗] 賽馬程式 (四)
本帖最後由 王瑞喻 於 2019-12-28 14:56 編輯
1. 在比賽首頁顯示第幾局
2. 在比賽結束頁顯示哪一位選手勝出
本帖隱藏的內容需要回復才可以瀏覽
作者:
洪子涵
時間:
2019-12-14 10:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
cout<<"[好事成雙]賽馬場\n----------------------------------------------------------|終點"<<endl;
cout<<"▲"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"●"<<endl;
system("pause");
system("cls");
srand(time(NULL));
int h[4]={0,0,0,0},win;
string n[4]={"▲","◆","★","●"};
while(true)
{
cout<<"比賽進行中\n------------------------------------------------------------|終點"<<endl;
int r=rand()%4;
h[r]++;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(h[r]==60){
win=r;
break;
}
_sleep(10);
system("cls");
}
system("cls");
cout<<"比賽結束";
cout<<"由"<<n[win]<<"先馳得點\n";
cout<<"------------------------------------------------------------|終點"<<endl;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
system("pause");
system("cls");
goto re;
return 0;
}
複製代碼
作者:
洪藜芸
時間:
2019-12-14 10:45
本帖最後由 洪藜芸 於 2019-12-14 11:04 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=1;
re:
int h[4]={0,0,0,0};
string w[4]={"◆","★","▲","●"};
int wi;
srand(time(NULL));
cout<<"賽馬場 第"<<a<<"局"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
int r=rand()%4;
h[r]++;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(h[r]==72)
{
wi=r;
break;
}
system("cls");
}
system("cls");
cout<<"比賽結束,由"<<w[wi]<<"獲勝"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●"<<endl;
a++;
system("pause");
system("cls");
goto re;
return 0;
}
作者:
鄭羽捷
時間:
2019-12-14 11:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
cout<<"[好事成雙]賽馬場\n----------------------------------------------------------|終點"<<endl;
cout<<"▲"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"●"<<endl;
system("pause");
system("cls");
srand(time(NULL));
int h[4]={0,0,0,0},win;
string n[4]={"▲","◆","★","●"};
while(true)
{
cout<<"比賽進行中\n------------------------------------------------------------|終點"<<endl;
int r=rand()%4;
h[r]++;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(h[r]==60){
win=r;
break;
}
_sleep(10);
system("cls");
}
system("cls");
cout<<"比賽結束";
cout<<"由"<<n[win]<<"先馳得點\n";
cout<<"------------------------------------------------------------|終點"<<endl;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
system("pause");
system("cls");
goto re;
return 0;
}
複製代碼
作者:
黃傳耀
時間:
2019-12-14 11:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int r,n=1 ;
srand(time(NULL));
re:
int h[4] = {0,0,0,0};
cout<<"賽馬場第"<<n<<"局"<<endl<<"----------------------------------------終點"<<endl;
cout<<"◆"<<endl<<"★"<<endl<<"▲"<<endl<<"●"<<endl;
system("pause");
system("cls");
while(true)
{
cout<<"比賽中"<<endl<<"----------------------------------------終點"<<endl;
r = rand()%4;
h[r]++;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★"<<endl;for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲"<<endl;for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(h[r]>=40)
{
_sleep(2000);
if(h[0]>=40)
cout<<"◆獲勝";
if(h[1]>=40)
cout<<"★獲勝";
if(h[2]>=40)
cout<<"▲獲勝";
if(h[3]>=40)
cout<<"●獲勝";
_sleep(1000);
break;
}
_sleep(10);
system("cls");
}
system("cls");
n++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
郭哲維
時間:
2019-12-14 11:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
cout<<"[好事成雙]賽馬場\n----------------------------------------------------------|終點"<<endl;
cout<<"▲"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"●"<<endl;
system("pause");
system("cls");
srand(time(NULL));
int h[4]={0,0,0,0},win;
string n[4]={"▲","◆","★","●"};
while(true)
{
cout<<"比賽進行中\n------------------------------------------------------------|終點"<<endl;
int r=rand()%4;
h[r]++;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(h[r]==60){
win=r;
break;
}
_sleep(10);
system("cls");
}
system("cls");
cout<<"比賽結束";
cout<<"由"<<n[win]<<"先馳得點\n";
cout<<"------------------------------------------------------------|終點"<<endl;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
system("pause");
system("cls");
goto re;
return 0;
}
複製代碼
作者:
林孟蓁
時間:
2019-12-14 11:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
cout<<"[好事成雙]賽馬場\n----------------------------------------------------------|終點"<<endl;
cout<<"▲"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"●"<<endl;
system("pause");
system("cls");
srand(time(NULL));
int h[4]={0,0,0,0},win;
string n[4]={"▲","◆","★","●"};
while(true)
{
cout<<"比賽進行中\n------------------------------------------------------------|終點"<<endl;
int r=rand()%4;
h[r]++;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(h[r]==60){
win=r;
break;
}
_sleep(10);
system("cls");
}
system("cls");
cout<<"比賽結束";
cout<<"由"<<n[win]<<"先馳得點\n";
cout<<"------------------------------------------------------------|終點"<<endl;
for(int i=0;i<=h[0];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=0;i<=h[1];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=0;i<=h[2];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=0;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
system("pause");
system("cls");
goto re;
return 0;
}
複製代碼
作者:
王翎璇
時間:
2019-12-14 11:22
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,r;
re:
int h[4]={0,0,0,0};
srand(time(NULL));
cout<<"「好事成雙」賽馬場,第"<<n<<"局"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
r=rand()%4;
h[r]++;
for(int i=1;i<=h[0];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(h[r]==72)
break;
system("cls");
}
system("cls");
cout<<"比賽結束";
if(r==0)
cout<<"由◆先抵達終點"<<endl;
if(r==1)
cout<<"由★先抵達終點"<<endl;
if(r==2)
cout<<"由▲先抵達終點"<<endl;
if(r==3)
cout<<"由●先抵達終點"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
for(int i=1;i<=h[0];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
system("pause");
system("cls");
n++;
goto re;
return 0;
}
複製代碼
作者:
黃傳耀
時間:
2019-12-14 17:49
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
int money=0,choose,buyin,down,r,n=1,again;
srand(time(NULL));
re:
int h[4] = {0,0,0,0};
cout<<"賽馬場\n---------------------------------------------------|終點\n◆\n★\n▲\n●\n";
cout<<"可用餘額:"<<money<<"元\n(1)買入 (2)下注 (3)進入比賽 (4)退出 請選擇:";
cin>>choose;
if(choose==1)
{
cout<<"要買入多少:";
cin>>buyin;
if(buyin<=0)
{
cout<<"不好意思,輸入錯誤";
}
else
{
money+=buyin;
}
_sleep(1500);
system("cls");
goto re;
}
else if(choose==2)
{
cout<<"要下注多少:";
cin>>down;
if(down<=0||down>money)
{
cout<<"不好意思,輸入錯誤";
}
else
{
money-=down;
}
_sleep(1500);
system("cls");
goto re;
}
else if(choose == 3)
{
_sleep(500);
system("cls");
goto re3;
}
else if(choose == 4)
goto re2;
else
{
cout<<"不好意思,輸入錯誤";
_sleep(1500);
system("cls");
goto re;
}
re3:
while(true)
{
cout<<"第"<<n<<"局比賽中\n---------------------------------------------------|終點\n";
r = rand()%4;
h[r]++;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆\n";
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★\n";
for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲\n";
for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●\n";
if(h[r]>=50)
{
if(r==0)
{
cout<<"◆獲勝";
}
if(r==1)
{
cout<<"★獲勝";
}if(r==2)
{
cout<<"▲獲勝";
}if(r==3)
{
cout<<"●獲勝";
}
_sleep(2000);
system("cls");
n++;
break;
}
_sleep(50);
system("cls");
}
re4:
cout<<"要繼續嗎? 1.要2.不要 請選擇:";
cin>>again;
if(again == 1)
{
goto re;
}
else if(again == 2)
{
goto re2;
}
else
{
cout<<"不好意思,輸入錯誤";
_sleep(1500);
system("cls");
goto re4;
}
re2:
system("pause");
return 0;
}
複製代碼
作者:
蔡少宇
時間:
2019-12-21 09:57
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,r;
re:
system("cls");
int h[4]={0,0,0,0};
srand(time(NULL));
cout<<"賽馬場 第"<<n<<"局"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
cout<<"比賽進行中"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
r=rand()%4;
h[r]++;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(h[r]==72)
{
break;
}
system("cls");
}
system("cls");
cout<<"比賽結束!!!";
if(r==0)
cout<<"由 ◆ 先馳得點"<<endl;
if(r==1)
cout<<"由 ★ 先馳得點"<<endl;
if(r==2)
cout<<"由 ▲ 先馳得點"<<endl;
if(r==3)
cout<<"由 ● 先馳得點"<<endl;
cout<<"-------------------------------------------------------------------------|終點"<<endl;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("pause");
n++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曾宥程
時間:
2019-12-21 09:58
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n=1,r;
re:
system("cls");
int h[4]={0,0,0,0};
srand(time(NULL));
cout<<"賽馬場 第"<<n<<"場"<<endl;
cout<<"------------------------------------------------------------------------|終點"<<endl;
cout<<"◆"<<endl<<"★"<<endl<<"▲"<<endl<<"●"<<endl; //72
system("pause");
system("cls");
while(true)
{
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------------------|終點"<<endl;
r=rand()%4;
h[r]++;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(h[r]==72)
break;
system("cls");
}
system("cls");
cout<<"比賽結束";
if(r==0)
cout<<"由◆獲得第一"<<endl;
if(r==1)
cout<<"由★獲得第一"<<endl;
if(r==2)
cout<<"由▲獲得第一"<<endl;
if(r==3)
cout<<"由●獲得第一"<<endl;
cout<<"------------------------------------------------------------------------|終點"<<endl;
r=rand()%4;
h[r]++;
for(int i=1;i<=h[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
{
cout<<" ";
}
cout<<"●"<<endl;
if(h[r]==72)
{
system("cls");
}
system("pause");
n++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
王建葦
時間:
2019-12-28 14:53
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int number=0;
re:
int h[4]={0,0,0,0},r;
number++;
srand(time(NULL));
cout<<"[好事雙城]賽馬場 第"<<number<<"局"<<endl;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
cout<<"比賽進行中...... 第("<<number<<")局"<<endl;
r=rand()%4;
h[r]++;
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=1;i<=h[0];i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1;i<=h[1];i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1;i<=h[2];i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1;i<=h[3];i++)
cout<<" ";
cout<<"●"<<endl;
if(h[r]==72)
{
break;
}
_sleep(1);
system("cls");
}
system("cls");
cout<<"比賽結束! ";
if(r==0)
{
cout<<"由◆取得領先"<<endl;
}else if(r==1)
{
cout<<"由★取得領先"<<endl;
}else if(r==2)
{
cout<<"由▲取得領先"<<endl;
}else
{
cout<<"由●取得領先"<<endl;
}
cout<<"-------------------------------------------------------------------------| 終點"<<endl;
for(int i=1; i<=h[0]; i++)
cout<<" ";
cout<<"◆"<<endl;
for(int i=1; i<=h[1]; i++)
cout<<" ";
cout<<"★"<<endl;
for(int i=1; i<=h[2]; i++)
cout<<" ";
cout<<"▲"<<endl;
for(int i=1; i<=h[3]; i++)
cout<<" ";
cout<<"●"<<endl;
system("pause");
system("cls");
goto re;
return 0;
}
複製代碼
作者:
駱顗安
時間:
2020-8-27 21:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int speed=10,n=1;
re:
system("cls");
int d[]={0,0,0,0};
cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
cout<<"-----------------------------------------------------------------| 終點"<<endl;
cout<<"●"<<endl;
cout<<"▲"<<endl;
cout<<"★"<<endl;
cout<<"◆"<<endl;
system("pause");
while(true)
{
system("cls");
cout<<"比賽進行中 第"<<n<<"局"<<endl;
cout<<"-----------------------------------------------------------------| 終點"<<endl;
int g=rand()%4;
d[g]++;
for(int a=0;a<=d[0];a++)
cout<<" ";
cout<<"●"<<endl;
for(int b=0;b<=d[1];b++)
cout<<" ";
cout<<"▲"<<endl;
for(int c=0;c<=d[2];c++)
cout<<" ";
cout<<"★"<<endl;
for(int e=0;e<=d[3];e++)
cout<<" ";
cout<<"◆"<<endl;
if(d[0]>=64||d[1]>=64||d[2]>=64||d[3]>=64)
{
system("cls");
cout<<"比賽結束 由";
if(d[0]>=64)
cout<<"●";
else if(d[1]>=64)
cout<<"▲";
else if(d[2]>=64)
cout<<"★";
else if(d[3]>=64)
cout<<"◆";
cout<<"先馳得點!"<<endl;
cout<<"-----------------------------------------------------------------| 終點"<<endl;
int g=rand()%4;
d[g]++;
for(int a=0;a<=d[0];a++)
cout<<" ";
cout<<"●"<<endl;
for(int b=0;b<=d[1];b++)
cout<<" ";
cout<<"▲"<<endl;
for(int c=0;c<=d[2];c++)
cout<<" ";
cout<<"★"<<endl;
for(int e=0;e<=d[3];e++)
cout<<" ";
cout<<"◆"<<endl;
n=n+1;
break;
}
_sleep(speed);
}
system("pause");
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2