- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int balance=0,money,n=1;
- int bet,buyin,option,winner,;
- re1:
- int a=0,b=0,c=0,d=0,r;
- system("cls");
- cout<<"$ 財源滾滾賽馬場 $ 第"<<n<<"局"<<endl;
- cout<<"---------------------------------------------------------------------|終點|"<<endl;
- cout<<"◥1◣"<<endl;
- cout<<"◥2◣"<<endl;
- cout<<"◥3◣"<<endl;
- cout<<"◥4◣"<<endl;
- cout<<endl<<"可用餘額: "<<balance<<"元"<<endl<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇: ";
- cin>>option;
- if(option==1)
- {
- cout<<"買入: ";
- cin>>buyin;
- balance+=buyin; //i+=2 i=i+2
- goto re1;
- }else if(option==2)
- {
- cout<<"下注: ";
- cin>>bet;
- if(bet>balance)
- {
- cout<<"可用餘額不足!請先買入!"<<endl<<endl;
- system("pause");
- goto re1;
- }else
- {
- cout<<endl<<"(1)◥1◣ (2)◥2◣ (3)◥3◣ (4)◥4◣ 請選擇: ";
- cin>>option;
- cout<<"比賽即將開始!"<<endl<<endl;
- }
- }else if(option==3)
- {
- goto end;
- }else
- {
- cout<<"輸入錯誤!"<<endl<<endl;
- system("pause");
- goto re1;
- }
- system("pause");
- system("cls");
- srand(time(NULL));
- while((a!=70)&&(b!=70)&&(c!=70)&&(d!=70))
- {
- r=rand()%4; //產生0~3之隨機亂數
- if(r==0)
- a++;
- if(r==1)
- b++;
- if(r==2)
- c++;
- if(r==3)
- d++;
- cout<<"比賽進行中"<<endl;
- cout<<"---------------------------------------------------------------------|終點|"<<endl;
- for(int i=1;i<=a;i++)
- cout<<" ";
- cout<<"◥1◣"<<endl;
- for(int i=1;i<=b;i++)
- cout<<" ";
- cout<<"◥2◣"<<endl;
- for(int i=1;i<=c;i++)
- cout<<" ";
- cout<<"◥3◣"<<endl;
- for(int i=1;i<=d;i++)
- cout<<" ";
- cout<<"◥4◣"<<endl;
- system("cls");
- }
- if(a>b && a>c && a>d)
- winner=1;
- else if(b>a && b>c && b>d)
- winner=2;
- else if(c>a && c>b && c>d)
- winner=3;
- else
- winner=4;
- cout<<"比賽結束! 由 "<<winner<<" 號選手先馳得點!"<<endl;
- cout<<"---------------------------------------------------------------------|終點|"<<endl;
- for(int i=1;i<=a;i++)
- cout<<" ";
- cout<<"◥1◣"<<endl;
- for(int i=1;i<=b;i++)
- cout<<" ";
- cout<<"◥2◣"<<endl;
- for(int i=1;i<=c;i++)
- cout<<" ";
- cout<<"◥3◣"<<endl;
- for(int i=1;i<=d;i++)
- cout<<" ";
- cout<<"◥4◣"<<endl;
- if(winner==option)
- {
- cout<<"贏了"<<bet*3<<"元!"<<endl;
- balance+=bet*3;
- money+=bet*3;
- }
- else
- {
- cout<<"輸了"<<bet<<"元!"<<endl;
- balance-=bet;
- money-=bet;
- }
- cout<<endl;
- n++;
- system("pause");
- goto re1;
- end:
- if(money==0)
- {
- cout<<"沒輸沒贏"<<endl;
- }
- if(money>0)
- {
- cout<<"輸了"<<money<<endl;
- }
- if(money<0)
- {
- cout<<"贏了"<<-money<<endl;
- }
- cout<<"謝謝光臨"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |