標題:
賽馬程式 (二)
[打印本頁]
作者:
陳品肇
時間:
2018-12-7 22:59
標題:
賽馬程式 (二)
本帖最後由 陳品肇 於 2018-12-8 17:19 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int a=0,b=0,c=0,d=0,r; //r 我隨機挑到馬匹
cout<<"「好事成雙」賽馬場"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
system("cls"); //清空畫面
srand(time(NULL)); //撒亂樹種子
while(a!=70 && b!=70 && c!=70&& d!=70) //判斷四隻馬只要有一隻到終點就跳離while
{
cout<<"賽馬進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
r = rand()%4+1; //產生1~4亂數 隨機挑馬1~4其中一隻
if(r==1)
a++;
if(r==2)
b++;
if(r==3)
c++;
if(r==4)
d++;
for(int i=0;i<=a;i++) //第一匹馬前進
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++) //第二匹馬前進
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++) //第三匹馬前進
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++) //第四匹馬前進
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls"); //清空畫面
}
cout<<"賽馬結束"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++) //第一匹馬最後的位子
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0;i<=b;i++) //第二匹馬最後的位子
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++) //第三匹馬最後的位子
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++) //第四匹馬最後的位子
{
cout<<" ";
}
cout<<"●"<<endl;
system("pause");
system("cls");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
戴安利
時間:
2018-12-8 17:29
本帖最後由 戴安利 於 2018-12-8 17:32 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=0, b=0, c=0, d=0, r;
cout<<"+++好事成雙->賽馬場+++"<<endl;
cout<<"-------------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
system("cls");
srand(time(NULL));
while(a!=20 && b!=20 && c!=20 && d!=20)
{
cout<<"賽馬進行中..."<<endl;
cout<<"-------------------------------------------|終點"<<endl;
r = rand()%4+1;
if(r==1)
a++;
if(r==2)
b++;
if(r==3)
c++;
if(r==4)
d++;
for(int i=0;i<=a;i++)
cout<<" ";
cout<<"◆"<<endl;
a++;
for(int i=0;i<=b;i++)
cout<<" ";
cout<<"★"<<endl;
b++;
for(int i=0;i<=c;i++)
cout<<" ";
cout<<"▲"<<endl;
c++;
for(int i=0;i<=d;i++)
cout<<" ";
cout<<"●"<<endl;
d++;
system("cls");
}
cout<<"賽馬結束..."<<endl;
cout<<"-------------------------------------------|終點"<<endl;
for(int i=0;i<=a;i++)
cout<<" ";
cout<<"◆"<<endl;
a++;
for(int i=0;i<=b;i++)
cout<<" ";
cout<<"★"<<endl;
b++;
for(int i=0;i<=c;i++)
cout<<" ";
cout<<"▲"<<endl;
c++;
for(int i=0;i<=d;i++)
cout<<" ";
cout<<"●"<<endl;
d++;
system("pause");
return 0;
}
複製代碼
作者:
陳柏霖
時間:
2018-12-8 17:30
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x=1;
re:
int a=0 ,b=0 ,c=0 ,d=0 ,z ;
srand(time(NULL));
cout<<"第"<<x<<"場[萬事如意]賽馬場"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"㊣"<<endl;
cout<<"▼"<<endl;
system("pause");
while(a!=75 && b!=75 && c!=75 && d!=75)
{
cout<<"比賽中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
z=rand()%4+1;
if(z==1)
{
a+=3;
}
if(z==2)
{
b+=3;
}
if(z==3)
{
c+=3;
}
if(z==4)
{
d+=3;
}
for(int i=0; i<=a; i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0; i<=b; i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0; i<=c; i++)
{
cout<<" ";
}
cout<<"㊣"<<endl;
for(int i=0; i<=d; i++)
{
cout<<" ";
}
cout<<"▼"<<endl;
system("cls");
}
cout<<"第"<<x<<"場比賽結束"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0; i<=a; i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int i=0; i<=b; i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0; i<=c; i++)
{
cout<<" ";
}
cout<<"㊣"<<endl;
for(int i=0; i<=d; i++)
{
cout<<" ";
}
cout<<"▼"<<endl;
cout<<"按任意鍵進行下一場比賽"<<endl;
system("pause");
system("cls");
x++;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
戴唯陞
時間:
2018-12-8 17:30
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int a=0,b=0,c=0,d=0,r;
cout<<"好事成雙""賽馬場"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
system("cls");
srand(time(NULL));
while(a!=100 && b!=100 && c!=100 && d!=100)
{
cout<<"賽馬進行中"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
r = rand()%4+1;
if(r==1)
a++;
if(r==2)
b++;
if(r==3)
c++;
if(r==4)
d++;
for (int i=0;i<=a;i++)
cout<<" ";
cout<<"◆"<<endl;
a++;
for (int i=0;i<=b;i++)
cout<<" ";
cout<<"★"<<endl;
b++;
for (int i=0;i<=c;i++)
cout<<" ";
cout<<"▲"<<endl;
c++;
for (int i=0;i<=d;i++)
cout<<" ";
cout<<"●"<<endl;
d++;
system("cls");
}
cout<<"賽馬結束"<<endl;
cout<<"------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"●"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
戴偉宸
時間:
2018-12-8 17:35
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int a=0,b=0,c=0,d=0,r;
cout<<"「好事成雙」賽馬場"<<endl;
cout<<"-----------------------------------------------------------------------| 終點"<<endl;
cout<<"+"<<endl;
cout<<"-"<<endl;
cout<<"*"<<endl;
cout<<"/"<<endl;
system("pause");
system("cls");
srand(time(NULL));
while(a!=69 && b!=69 && c!=69&& d!=69)
{
cout<<"賽馬進行中"<<endl;
cout<<"-----------------------------------------------------------------------| 終點"<<endl;
r = rand()%4+1;
if(r==1)
a++;
if(r==2)
b++;
if(r==3)
c++;
if(r==4)
d++;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"+"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"-"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"*"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"/"<<endl;
system("cls");
}
cout<<"賽馬結束"<<endl;
cout<<"-----------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=a;i++)
{
cout<<" ";
}
cout<<"+"<<endl;
for(int i=0;i<=b;i++)
{
cout<<" ";
}
cout<<"-"<<endl;
for(int i=0;i<=c;i++)
{
cout<<" ";
}
cout<<"*"<<endl;
for(int i=0;i<=d;i++)
{
cout<<" ";
}
cout<<"/"<<endl;
system("pause");
system("cls");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蔡依宸
時間:
2018-12-10 19:36
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int space[4]={0,0,0,0};
srand(time(NULL));
cout<<"沒錢馬賽場"<<endl;
cout<<"--------------------------------------------------------------------終點"<<endl;
cout<<"☆"<<endl;
cout<<"▽"<<endl;
cout<<"◆"<<endl;
cout<<"㊣"<<endl;
system("pause");
while(true)
{
int r=rand()%4;
space[r]++;
if(space[r]==30)
break;
cout<<"比賽進行中"<<endl;
cout<<"------------------------------------------------------------終點"<<endl;
for(int j=0;j<space[0];j++)
cout<<" ";
cout<<"☆"<<endl;
for(int j=0;j<space[1];j++)
cout<<" ";
cout<<"▽"<<endl;
for(int j=0;j<space[2];j++)
cout<<" ";
cout<<"◆"<<endl;
for(int j=0;j<space[3];j++)
cout<<" ";
cout<<"㊣"<<endl;
system("cls");
}
cout<<"比賽結束"<<endl;
cout<<"----------------------------------------------------------終點"<<endl;
for(int j=0;j<space[0];j++)
cout<<" ";
cout<<"☆"<<endl;
for(int j=0;j<space[1];j++)
cout<<" ";
cout<<"▽"<<endl;
for(int j=0;j<space[2];j++)
cout<<" ";
cout<<"◆"<<endl;
for(int j=0;j<space[3];j++)
cout<<" ";
cout<<"㊣"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡季庭
時間:
2018-12-10 20:03
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int space[4]={0,0,0,0};
srand(time(NULL));
cout<<"[好棒棒]賭賽馬場"<<endl;
cout<<"-------------------------------------|終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while(true)
{
int r=rand()%4;
space[r]++;
if(space[r]==34)
break;
cout<<"比賽進行中"<<endl;
cout<<"----------------------------------|終點"<<endl;
for(int j=0;j<space[0];j++)
cout<<" ";
cout<<"◆"<<endl;
for(int j=0;j<space[1];j++)
cout<<" ";
cout<<"★"<<endl;
for(int j=0;j<space[2];j++)
cout<<" ";
cout<<"▲"<<endl;
for(int j=0;j<space[3];j++)
cout<<" ";
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束"<<endl;
cout<<"----------------------------------|終點"<<endl;
for(int j=0;j<space[0];j++)
cout<<" ";
cout<<"◆"<<endl;
for(int j=0;j<space[1];j++)
cout<<" ";
cout<<"★"<<endl;
for(int j=0;j<space[2];j++)
cout<<" ";
cout<<"▲"<<endl;
for(int j=0;j<space[3];j++)
cout<<" ";
cout<<"●"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
譚詩澐
時間:
2018-12-12 17:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int space[]={0,0,0,0};
cout<<"賽馬場"<<endl;
cout<<"------------------------------------------------------------------------------| 終點"<<endl;
cout<<"◆"<<endl;
cout<<"★"<<endl;
cout<<"▲"<<endl;
cout<<"●"<<endl;
system("pause");
while (true)
{
int r=rand()%4;
space[r]++;
if(space[r]==74)
break;
cout<<"比賽進行中"<<endl;
cout<<"--------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=space[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int j=0;j<=space[1]; j++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int j=0;j<=space[2];j++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int j=0;j<=space[3];j++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("cls");
}
cout<<"比賽結束"<<endl;
cout<<"--------------------------------------------------------------------------| 終點"<<endl;
for(int i=0;i<=space[0];i++)
{
cout<<" ";
}
cout<<"◆"<<endl;
for(int j=0;j<=space[1]; j++)
{
cout<<" ";
}
cout<<"★"<<endl;
for(int j=0;j<=space[2];j++)
{
cout<<" ";
}
cout<<"▲"<<endl;
for(int j=0;j<=space[3];j++)
{
cout<<" ";
}
cout<<"●"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2