返回列表 發帖

賽馬程式 (二)

本帖最後由 tonyh 於 2013-10-12 15:25 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=0,b=0,c=0,d=0,r;
  7.     cout<<"$ 財源滾滾賽馬場 $"<<endl;
  8.     cout<<"---------------------------------------------------------------------|終點|"<<endl;
  9.     cout<<"◥1◣"<<endl;
  10.     cout<<"◥2◣"<<endl;
  11.     cout<<"◥3◣"<<endl;
  12.     cout<<"◥4◣"<<endl;
  13.     system("pause");
  14.     system("cls");
  15.     srand(time(NULL));
  16.     while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
  17.     {
  18.         r=rand()%4;    //產生0~3之隨機亂數
  19.         if(r==0)
  20.             a++;
  21.         if(r==1)
  22.             b++;
  23.         if(r==2)
  24.             c++;
  25.         if(r==3)
  26.             d++;
  27.         cout<<"比賽進行中"<<endl;
  28.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  29.         for(int i=1;i<=a;i++)
  30.             cout<<" ";
  31.         cout<<"◥1◣"<<endl;
  32.         for(int i=1;i<=b;i++)
  33.             cout<<" ";
  34.         cout<<"◥2◣"<<endl;
  35.         for(int i=1;i<=c;i++)
  36.             cout<<" ";
  37.         cout<<"◥3◣"<<endl;
  38.         for(int i=1;i<=d;i++)
  39.             cout<<" ";
  40.         cout<<"◥4◣"<<endl;
  41.         system("cls");
  42.     }
  43.         cout<<"比賽結束"<<endl;
  44.         cout<<"---------------------------------------------------------------------|終點|"<<endl;
  45.         for(int i=1;i<=a;i++)
  46.             cout<<" ";
  47.         cout<<"◥1◣"<<endl;
  48.         for(int i=1;i<=b;i++)
  49.             cout<<" ";
  50.         cout<<"◥2◣"<<endl;
  51.         for(int i=1;i<=c;i++)
  52.             cout<<" ";
  53.         cout<<"◥3◣"<<endl;
  54.         for(int i=1;i<=d;i++)
  55.             cout<<" ";
  56.         cout<<"◥4◣"<<endl;  
  57.     system("pause");   
  58.     return 0;
  59. }
複製代碼

返回列表