本帖最後由 陳品肇 於 2019-4-27 13:46 編輯
加入首頁選單, 新增買入的功能, 執行畫面如下:
可用餘額: 0 元
(1)買入 (2)下注 (3)離開 請選擇: 1
買入: 200
在使用者輸入數值後, 畫面更新如下:
可用餘額: 200 元
(1)買入 (2)下注 (3)離開 請選擇:- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int n=1,balance=0;
- re:
- int a=0, b=0, c=0, d=0, r, option, buyin;
- system("cls");
- cout<<"「好事成雙」賽馬場 第 "<<n<<" 局"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- cout<<endl;
- cout<<"可用餘額: "<<balance<<"元"<<endl<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
- cin>>option;
- if(option==1)
- {
- cout<<"買入: ";
- cin>>buyin;
- balance+=buyin; //balance=balance+buyin
- goto re;
- }
- system("pause");
- system("cls");
- srand(time(NULL));
- while(a!=75 && b!=75 && c!=75 && d!=75)
- {
- r=rand()%4; //產生0~3之隨機亂數
- if(r==0)
- a++;
- else if(r==1)
- b++;
- else if(r==2)
- c++;
- else
- d++;
- cout<<"比賽進行中"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=1; i<=a; i++)
- cout<<" ";
- cout<<"◆"<<endl;
- for(int i=1; i<=b; i++)
- cout<<" ";
- cout<<"★"<<endl;
- for(int i=1; i<=c; i++)
- cout<<" ";
- cout<<"▲"<<endl;
- for(int i=1; i<=d; i++)
- cout<<" ";
- cout<<"●"<<endl;
- system("cls");
- }
- cout<<"比賽結束! 由 ";
- if(a==75)
- cout<<"◆";
- else if(b==75)
- cout<<"★";
- else if(c==75)
- cout<<"▲";
- else
- cout<<"●";
- cout<<" 先馳得點!"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=1; i<=a; i++)
- cout<<" ";
- cout<<"◆"<<endl;
- for(int i=1; i<=b; i++)
- cout<<" ";
- cout<<"★"<<endl;
- for(int i=1; i<=c; i++)
- cout<<" ";
- cout<<"▲"<<endl;
- for(int i=1; i<=d; i++)
- cout<<" ";
- cout<<"●"<<endl;
- system("pause");
- n++;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |