返回列表 發帖

賽馬程式 (二)

1. 在比賽首頁顯示第幾局
2. 在比賽結束頁顯示哪一位選手勝出



  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.   int times=1;
  8.   while(true)
  9.   {
  10.     int horse1=0, horse2=0, horse3=0, horse4=0, random=0;
  11.     srand(time(NULL));
  12.     system("cls");
  13.     cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  14.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  15.     cout<<"◆"<<endl;
  16.     cout<<"★"<<endl;
  17.     cout<<"▲"<<endl;
  18.     cout<<"●"<<endl;
  19.     system("pause");
  20.     system("cls");
  21.    
  22.     while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  23.     {
  24.         random=rand()%4;   //產生0~3之隨機亂數
  25.         if(random==0) {
  26.            horse1++;
  27.         }  
  28.         else if(random==1) {
  29.            horse2++;
  30.         }
  31.         else if(random==2) {
  32.            horse3++;
  33.         }
  34.         else if(random==3) {
  35.            horse4++;
  36.         }
  37.         cout<<"比賽進行中"<<endl;
  38.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  39.       
  40.         for(int i=1; i<=horse1; i++) {
  41.            cout<<" ";
  42.         }   
  43.         cout<<"◆"<<endl;
  44.         
  45.         for(int i=1; i<=horse2; i++) {
  46.            cout<<" ";
  47.         }   
  48.         cout<<"★"<<endl;
  49.         
  50.          for(int i=1; i<=horse3; i++) {
  51.            cout<<" ";
  52.         }   
  53.         cout<<"▲"<<endl;
  54.         
  55.          for(int i=1; i<=horse4; i++) {
  56.            cout<<" ";
  57.         }   
  58.         cout<<"●"<<endl;
  59.         system("cls");      
  60.     }
  61.     times++;
  62.     system("cls");     
  63.     cout<<"比賽結束! 由 ";
  64.     if(horse1 == 75) {
  65.       cout<< "◆" << "先馳得點" << endl;      
  66.     }
  67.     else if (horse2 == 75) {
  68.       cout<< "★" << "先馳得點" << endl;      
  69.     }
  70.     else if (horse3 == 75) {
  71.       cout<< "▲" << "先馳得點" << endl;      
  72.     }
  73.     else if (horse4 == 75) {
  74.       cout<< "●" << "先馳得點" << endl;      
  75.     }
  76.      
  77.       cout<<"------------------------------------------------------------------------| 終點"<<endl;
  78.       
  79.         for(int i=1; i<=horse1; i++) {
  80.            cout<<" ";
  81.         }   
  82.         cout<<"◆"<<endl;
  83.         
  84.         for(int i=1; i<=horse2; i++) {
  85.            cout<<" ";
  86.         }   
  87.         cout<<"★"<<endl;
  88.         
  89.          for(int i=1; i<=horse3; i++) {
  90.            cout<<" ";
  91.         }   
  92.         cout<<"▲"<<endl;
  93.         
  94.          for(int i=1; i<=horse4; i++) {
  95.            cout<<" ";
  96.         }   
  97.         cout<<"●"<<endl;
  98.     system("pause");
  99. }

  100.     system("pause");
  101.     return 0;
  102.       
  103. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

返回列表