標題:
[作業] 賽馬程式 (三)
[打印本頁]
作者:
tonyh
時間:
2013-10-12 15:17
標題:
[作業] 賽馬程式 (三)
本帖最後由 tonyh 於 2013-10-26 14:25 編輯
使在比賽結束後, 程式能判斷出哪位選手勝出.
提示: 判斷變數 a, b, c, 還是 d, 誰比較大
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int winner;
int a=0,b=0,c=0,d=0,r;
cout<<"$ 財源滾滾賽馬場 $"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
cout<<"◥1◣"<<endl;
cout<<"◥2◣"<<endl;
cout<<"◥3◣"<<endl;
cout<<"◥4◣"<<endl;
system("pause");
system("cls");
srand(time(NULL));
while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
{
r=rand()%4; //產生0~3之隨機亂數
if(r==0)
a++;
if(r==1)
b++;
if(r==2)
c++;
if(r==3)
d++;
cout<<"比賽進行中"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("cls");
}
if(a>b && a>c && a>d)
winner=1;
else if(b>a && b>c && b>d)
winner=2;
else if(c>a && c>b && c>d)
winner=3;
else
winner=4;
cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林以諾
時間:
2013-10-12 16:24
本帖最後由 林以諾 於 2013-10-26 14:23 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int winner;
int a=0,b=0,c=0,d=0,r;
cout<<"『以諾帥哥』賽馬場!!"<<endl;
cout<<"-----------------------------------------------------------|終點"<<endl;
cout<<"◥1◣"<<endl;
cout<<"◥2◣"<<endl;
cout<<"◥3◣"<<endl;
cout<<"◥4◣"<<endl;
system("pause");
srand(time(NULL));
while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
{
r=rand()%4;
if(r==0)
a++;
else if(r==1)
b++;
else if(r==2)
c++;
else
d++;
cout<<"比賽進行中....";
cout<<endl<<"-----------------------------------------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("cls");
}
if(a>b&&a>c&&a>d)
winner=1;
else if(b>a&&b>c&&b>d)
winner=2;
else if(c>a&&c>b&&c>d)
winner=3;
else
winner=4;
cout<<"比賽結束!由"<<winner<<"號選手獲得勝利"<<endl;
cout<<endl<<"-----------------------------------------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
鎧言
時間:
2013-10-12 17:06
本帖最後由 鎧言 於 2013-10-26 14:32 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int winner;
int a=0,b=0,c=0,d=0,r;
cout<<"$ 財源滾滾賽馬場 $"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
cout<<"◥1◣"<<endl;
cout<<"◥2◣"<<endl;
cout<<"◥3◣"<<endl;
cout<<"◥4◣"<<endl;
system("pause");
system("cls");
srand(time(NULL));
while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
{
r=rand()%4; //產生0~3之隨機亂數
if(r==0)
a++;
if(r==1)
b++;
if(r==2)
c++;
if(r==3)
d++;
cout<<"比賽進行中"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("cls");
}
if(a>b && a>c && a>d)
winner=1;
else if(b>a && b>c && b>d)
winner=2;
else if(c>a && c>b && c>d)
winner=3;
else
winner=4;
cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃崇維
時間:
2013-10-12 17:16
本帖最後由 黃崇維 於 2013-10-26 14:30 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int winner;
int a=0,b=0,c=0,d=0,r;
cout<<"『玩到爽』賽場"<<endl;
cout<<"----------------------------------------------------終點"<<endl;
cout<<"◥1◣"<<endl;
cout<<"◥2◣"<<endl;
cout<<"◥3◣"<<endl;
cout<<"◥4◣"<<endl;
system("pause");
srand(time(NULL));
while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
{
r=rand()%4;
if(r==0)
a++;
else if(r==1)
b++;
else if(r==2)
c++;
else
d++;
cout<<"比賽進行中...";
cout<<endl<<"-----------------------------------------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("cls");
}
if(a>b&&a>c&&a>d)
winner=1;
else if(b>a&&b>c&&b>d)
winner=2;
else if(c>a&&c>b&&c>d)
winner=3;
else
winner=4;
cout<<"比賽結束!由"<<winner<<"號選手拿到勝利--------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張瀚仁
時間:
2013-10-15 22:06
本帖最後由 張瀚仁 於 2013-10-26 14:27 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=0 ,b=0, c=0, d=0,r,bigger,biggest,more;
cout<<"*準備輸光吧賽馬場*"<<endl;
cout<<endl<<"-----------------------------------------------------------------------|終點|"<<endl;
cout<<"◢1◤"<<endl;
cout<<"◢2◤"<<endl;
cout<<"◢3◤"<<endl;
cout<<"◢4◤"<<endl;
system("pause");
system("cls");
srand(time(NULL));
while((a!=65) && (b!=65) && (c!=65) && (d!=65))
{
r=rand()%4;
if(r==0)
a++;
else if(r==1)
b++;
else if(r==2)
c++;
else if(r==3)
d++;
cout<<"比賽進行中"<<endl;
cout<<endl<<"-----------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◢1◤"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◢2◤"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◢3◤"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◢4◤"<<endl;
system("cls");
}
more=(a>b)?a:b;
bigger=(c>d)?c:d;
biggest=(bigger>more)?bigger:more;
if(biggest==a)
cout<<"1號勝利"<<endl;
else if(biggest==b)
cout<<"2號勝利"<<endl;
else if(biggest==c)
cout<<"3號勝利"<<endl;
else if(biggest==d)
cout<<"4號勝利"<<endl;
cout<<endl<<"-----------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◢1◤"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◢2◤"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◢3◤"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◢4◤"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉泳鱔
時間:
2013-10-26 12:46
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int winner;
int a=0,b=0,c=0,d=0,r;
cout<<">讓你輸光光<賽場"<<endl;
cout<<"----------------------------------------------------終點"<<endl;
cout<<"◥1◣"<<endl;
cout<<"◥2◣"<<endl;
cout<<"◥3◣"<<endl;
cout<<"◥4◣"<<endl;
system("pause");
srand(time(NULL));
while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
{
r=rand()%4;
if(r==0)
a++;
else if(r==1)
b++;
else if(r==2)
c++;
else
d++;
cout<<"比賽進行中...";
cout<<endl<<"-----------------------------------------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("cls");
}
if(a>b&&a>c&&a>d)
winner=1;
else if(b>a&&b>c&&b>d)
winner=2;
else if(c>a&&c>b&&c>d)
winner=3;
else
winner=4;
cout<<"比賽結束!"<<endl;
cout<<"是"<<winner<<"號選手贏了!!!"<<endl;
cout<<endl<<"-----------------------------------------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
郭凡瑛
時間:
2013-10-26 14:29
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int winner;
int a=0,b=0,c=0,d=0,r;
cout<<"$ 財源滾滾賽馬場 $"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
cout<<"◥1◣"<<endl;
cout<<"◥2◣"<<endl;
cout<<"◥3◣"<<endl;
cout<<"◥4◣"<<endl;
system("pause");
system("cls");
srand(time(NULL));
while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
{
r=rand()%4; //產生0~3之隨機亂數
if(r==0)
a++;
if(r==1)
b++;
if(r==2)
c++;
if(r==3)
d++;
cout<<"比賽進行中"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("cls");
}
if(a>b && a>c && a>d)
winner=1;
else if(b>a && b>c && b>d)
winner=2;
else if(c>a && c>b && c>d)
winner=3;
else
winner=4;
cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
cout<<"---------------------------------------------------------------------|終點|"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃柏維
時間:
2013-10-26 14:31
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=0,b=0,c=0,d=0,r,winner;
cout<<"李奧斯本 賽馬場"<<endl;
cout<<"$-----------------------------------------------------------------||終點||"<<endl;
cout<<"◥1◣"<<endl;
cout<<"◥2◣"<<endl;
cout<<"◥3◣"<<endl;
cout<<"◥4◣"<<endl<<endl;
system("pause");
srand(time(NULL));
while((a!=68)&&(b!=68)&&(c!=68)&&(d!=68))
{
r=rand()%4;
if(r==0)
a++;
if(r==1)
b++;
if(r==2)
c++;
if(r==3)
d++;
cout<<"比賽進行中...";
cout<<endl<<"$-----------------------------------------------------------------||終點||"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
system("cls");
}
cout<<"比賽結束";
cout<<endl<<"$-----------------------------------------------------------------||終點||"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"◥1◣"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"◥2◣"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"◥3◣"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"◥4◣"<<endl;
if(a>b && a>c && a>d)
{
winner=1;
}
else if(a<b && b>c && b>d)
{
winner=2;
}
else if(a<c && c>b && c>d)
{
winner=3;
}
else
{
winner=4;
}
cout<<"比賽結果為 "<<winner<<" 號勝利"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
許逸群
時間:
2013-10-31 21:09
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string winner;
int a=0 ,b=0, c=0, d=0,r;
cout<<"$ 老師同學賽馬場(賭老師的必輸光用看的就知道) $"<<endl;
cout<<"-----------------------------------------------------------------|終點"<<endl;
cout<<"~老師"<<endl;
cout<<"~~~~~逸群"<<endl;
cout<<"~~~~以諾"<<endl;
cout<<"~~~凱言"<<endl;
srand(time(NULL));
system("pause");
while((a!=60)&&(b!=60)&&(c!=60)&&(d!=60))
{
r=rand()%4;
if(r==0)
a++;
else if(r==1)
b++;
else if(r==2)
c++;
else
d++;
cout<<"比賽進行中....";
cout<<endl<<"-----------------------------------------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"~老師"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"~~~~~逸群"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"~~~~以諾"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"~~~凱言"<<endl;
system("cls");
if(a>b && a>c && a>d)
winner="老師";
else if(b>a && b>c && b>d)
winner="逸群";
else if(c>a && c>b && c>d)
winner="以諾";
else
winner="凱言"; }
cout<<"比賽結束! 由 "<<winner<<" 選手先馳得點!"<<endl;
cout<<endl<<"-----------------------------------------------------------|終點"<<endl;
for(int i=1;i<=a;i++)
cout<<" ";
cout<<"~老師"<<endl;
for(int i=1;i<=b;i++)
cout<<" ";
cout<<"~~~~~逸群"<<endl;
for(int i=1;i<=c;i++)
cout<<" ";
cout<<"~~~~以諾"<<endl;
for(int i=1;i<=d;i++)
cout<<" ";
cout<<"~~~凱言"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2