返回列表 發帖

賽馬程式 "一匹馬"

本帖最後由 歐柏罕 於 2017-10-3 19:20 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re1:
  7.     int a=0, b=0, c=0, d=0, r=0;  //四匹馬 和 隨機產生的步數
  8.     system("cls");
  9.     cout<<"「好事成雙」賽馬場"<<endl;
  10.     cout<<"------------------------------------------------------------------------| 終點"<<endl;
  11.     cout<<"◆"<<endl;
  12.     cout<<"★"<<endl;
  13.     cout<<"▲"<<endl;
  14.     cout<<"●"<<endl;
  15.     system("pause");
  16.     system("cls");//再清除一次
  17.    
  18.     while(a!=75 && b!=75 && c!=75 && d!=75) //當到達終點(75)的時候跳離while迴圈
  19.     {
  20.         r=rand()%4;   //產生0~3之隨機亂數
  21.         if(r==0)
  22.             a++; //a=a+1
  23.             
  24.         cout<<"比賽進行中"<<endl; //cout比賽的畫面
  25.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  26.         
  27.         for(int i=1; i<=a; i++)
  28.             cout<<" "; //前面的空白
  29.         cout<<"◆"<<endl;  //這匹馬: 空白+空白+....+ "◆"
  30.         system("cls");      
  31.     }
  32.       
  33. }
複製代碼

返回列表