Board logo

標題: 賽馬程式 (四) [打印本頁]

作者: 李知易    時間: 2025-1-9 21:42     標題: 賽馬程式 (四)

本帖最後由 李知易 於 2025-1-17 18:58 編輯

加入首頁選單, 新增買入的功能, 執行畫面如下:


在使用者輸入數值後, 畫面更新如下:


[attach]20420[/attach][attach]20421[/attach][attach]20422[/attach]
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     int n=1, balance=0;
  8.     int option, buyin;
  9.     re:
  10.     system("cls");
  11.     srand(time(NULL));
  12.     int s[]={0,0,0,0};
  13.     string p[]={"◆","★","▲","●"};
  14.     int r=0;
  15.     cout<<"「好事成雙」賽馬場  第 "<<n<<" 局"<<endl;
  16.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  17.     for(int i=0; i<4; i++)
  18.         cout<<p[i]<<endl;
  19.     cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
  20.     cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
  21.     cin>>option;
  22.     if(option==1)
  23.     {
  24.         cout<<"買入: ";
  25.         cin>>buyin;
  26.         balance+=buyin;
  27.         goto re;         
  28.     }
  29.     system("cls");
  30.     while(s[r]<=73)
  31.     {
  32.         r=rand()%4;   //0~3
  33.         s[r]++;
  34.         cout<<"比賽進行中"<<endl;
  35.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  36.         for(int i=0; i<4; i++)
  37.         {
  38.             for(int j=0; j<s[i]; j++)
  39.                 cout<<" ";
  40.             cout<<p[i]<<endl;
  41.         }
  42.         _sleep(50);
  43.         system("cls");
  44.     }
  45.     cout<<"比賽結束!  由 "<<p[r]<<" 先馳得點!"<<endl;
  46.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  47.     for(int i=0; i<4; i++)
  48.     {
  49.         for(int j=0; j<s[i]; j++)
  50.             cout<<" ";
  51.         cout<<p[i]<<endl;
  52.     }
  53.     system("pause");
  54.     n++;
  55.     goto re;
  56.     return 0;
  57. }
複製代碼

作者: 張詠博    時間: 2025-1-12 08:43

此帖僅作者可見
作者: 彭郁程    時間: 2025-1-17 19:03

此帖僅作者可見
作者: 楊昀瑾    時間: 2025-1-17 19:03

此帖僅作者可見
作者: 朱立人    時間: 2025-1-17 19:06

此帖僅作者可見
作者: 洪睿輿    時間: 2025-1-17 19:13

此帖僅作者可見
作者: 吳孟樵    時間: 2025-1-17 19:14

此帖僅作者可見
作者: 江立辰    時間: 2025-1-17 19:14

此帖僅作者可見
作者: 鄭子宸    時間: 2025-1-17 19:31

此帖僅作者可見
作者: 陳頎諠    時間: 2025-1-17 19:34

此帖僅作者可見
作者: 黃品錡    時間: 2025-1-17 19:44

此帖僅作者可見
作者: 陳婕愉    時間: 2025-1-17 19:48

此帖僅作者可見




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2