返回列表 發帖

賽馬程式 "四匹馬PK"

請將程式修改成四匹馬PK
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.   
  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<<"「好事成雙」賽馬場"<<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. }

  62.     system("pause");
  63.     return 0;
  64.       
  65. }
複製代碼

返回列表