返回列表 發帖

賽馬程式 (三)

本帖最後由 歐柏罕 於 2017-10-24 18:49 編輯
  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.     int balance=0; //錢包
  12.     int option=0; //讓他做選擇  ,ABC => string
  13.     int buyin=0; //輸入的錢
  14.     while(option == 0 or option ==1) //第一次或是買入
  15.     {
  16.       srand(time(NULL));
  17.       system("cls");
  18.       cout<<"「好事成雙」賽馬場   " << "第 " <<times << "局 "<<endl;
  19.       cout<<"------------------------------------------------------------------------| 終點"<<endl;
  20.       cout<<"◆"<<endl;
  21.       cout<<"★"<<endl;  
  22.       cout<<"▲"<<endl;
  23.       cout<<"●"<<endl;
  24.    
  25.       cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;   
  26.       cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
  27.       cin>>option;
  28.       if(option==1)
  29.       {
  30.           cout<<"買入: ";
  31.           cin>>buyin;
  32.           balance+=buyin;           
  33.       }
  34.       system("pause");
  35.       system("cls");
  36.     }
  37.    
  38.     while(horse1!=75 && horse2!=75 && horse3!=75 && horse4!=75)
  39.     {
  40.          
  41.         random=rand()%4;   //產生0~3之隨機亂數
  42.         if(random==0) {
  43.            horse1++;
  44.         }  
  45.         else if(random==1) {
  46.            horse2++;
  47.         }
  48.         else if(random==2) {
  49.            horse3++;
  50.         }
  51.         else if(random==3) {
  52.            horse4++;
  53.         }
  54.         cout<<"比賽進行中"<<endl;
  55.         cout<<"------------------------------------------------------------------------| 終點"<<endl;
  56.       
  57.         for(int i=1; i<=horse1; i++) {
  58.            cout<<" ";
  59.         }   
  60.         cout<<"◆"<<endl;
  61.         
  62.         for(int i=1; i<=horse2; i++) {
  63.            cout<<" ";
  64.         }   
  65.         cout<<"★"<<endl;
  66.         
  67.          for(int i=1; i<=horse3; i++) {
  68.            cout<<" ";
  69.         }   
  70.         cout<<"▲"<<endl;
  71.         
  72.          for(int i=1; i<=horse4; i++) {
  73.            cout<<" ";
  74.         }   
  75.         cout<<"●"<<endl;
  76.         system("cls");      
  77.     }
  78.     times++;
  79.     system("cls");     
  80.     cout<<"比賽結束! 由 ";
  81.     if(horse1 == 75) {
  82.       cout<< "◆" << "先馳得點" << endl;      
  83.     }
  84.     else if (horse2 == 75) {
  85.       cout<< "★" << "先馳得點" << endl;      
  86.     }
  87.     else if (horse3 == 75) {
  88.       cout<< "▲" << "先馳得點" << endl;      
  89.     }
  90.     else if (horse4 == 75) {
  91.       cout<< "●" << "先馳得點" << endl;      
  92.     }
  93.      
  94.       cout<<"------------------------------------------------------------------------| 終點"<<endl;
  95.       
  96.         for(int i=1; i<=horse1; i++) {
  97.            cout<<" ";
  98.         }   
  99.         cout<<"◆"<<endl;
  100.         
  101.         for(int i=1; i<=horse2; i++) {
  102.            cout<<" ";
  103.         }   
  104.         cout<<"★"<<endl;
  105.         
  106.          for(int i=1; i<=horse3; i++) {
  107.            cout<<" ";
  108.         }   
  109.         cout<<"▲"<<endl;
  110.         
  111.          for(int i=1; i<=horse4; i++) {
  112.            cout<<" ";
  113.         }   
  114.         cout<<"●"<<endl;
  115.     system("pause");
  116. }

  117.     system("pause");
  118.     return 0;
  119.       
  120. }
複製代碼

返回列表