- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int n=1,money=0,total=0;
- re:
- int a=0,b=0,c=0,d=0,r,option,buyin,bet,horse,winner;
- system("cls");
- cout<<"「好事成雙」賽馬場 第"<<n<<"局"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- cout<<"\n可用金額:"<<money<<"元\n"<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
- cin>>option;
- if(option==1)
- {
- cout<<"請買入:";
- cin>>buyin;
- if(buyin<0)
- {
- cout<<"您輸入的金額有誤,請重新買入!"<<endl;
- }
- money+=buyin;
- goto re;
- }
- else if(option==2)
- {
- cout<<"請下注:";
- cin>>bet;
- if(bet>money)
- {
- cout<<"您的金額不足,請重新下注!"<<endl;
- system("pause");
- goto re;
- }
- else if(bet>=0 && bet<=money)
- {
- cout<<"(1)◆ (2)★ (3)▲ (4)● 請選擇:";
- cin>>horse;
- if(horse!=1 && horse!=2 && horse!=3 && horse!=4)
- {
- cout<<"您輸入的編號有誤,請重新選擇!"<<endl;
- system("pause");
- goto re;
- }
- else
- {
- cout<<"比賽即將開始!\n\n";
- }
- }
- else
- {
- cout<<"您輸入的金額有誤,請重新下注!"<<endl;
- system("pause");
- goto re;
- }
- }
- else if(option==3)
- {
- goto end;
- }
- else
- {
- cout<<"您輸入錯誤,請重新選擇!"<<endl;
- system("pause");
- goto re;
- }
- system("pause");
- system("cls");
- srand(time(NULL));
- while(a!=70 && b!=70 && c!=70 && d!=70)
- {
- cout<<"比賽進行中"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- r=rand()%4+1;
- if(r==1)
- {
- a++;
- }
- if(r==2)
- {
- b++;
- }
- if(r==3)
- {
- c++;
- }
- if(r==4)
- {
- d++;
- }
- for(int i=0;i<=a;i++)
- {
- cout<<" ";
- }
- cout<<"◆"<<endl;
- for(int i=0;i<=b;i++)
- {
- cout<<" ";
- }
- cout<<"★"<<endl;
- for(int i=0;i<=c;i++)
- {
- cout<<" ";
- }
- cout<<"▲"<<endl;
- for(int i=0;i<=d;i++)
- {
- cout<<" ";
- }
- cout<<"●"<<endl;
- system("cls");
- }
- cout<<"比賽結束!由";
- if(a==70)
- {
- cout<<"◆";
- winner=1;
- }
- if(b==70)
- {
- cout<<"★";
- winner=2;
- }
- if(c==70)
- {
- cout<<"▲";
- winner=3;
- }
- if(d==70)
- {
- cout<<"●";
- winner=4;
- }
- cout<<"先馳得點!"<<endl;
- cout<<"------------------------------------------------------------------------| 終點"<<endl;
- for(int i=0;i<=a;i++)
- {
- cout<<" ";
- }
- cout<<"◆"<<endl;
- for(int i=0;i<=b;i++)
- {
- cout<<" ";
- }
- cout<<"★"<<endl;
- for(int i=0;i<=c;i++)
- {
- cout<<" ";
- }
- cout<<"▲"<<endl;
- for(int i=0;i<=d;i++)
- {
- cout<<" ";
- }
- cout<<"●"<<endl;
- if(horse==winner)
- {
- money+=bet*3;
- cout<<"贏了"<<bet*3<<"元!"<<endl;
- total+=bet*3;
- }
- else
- {
- money-=bet;
- cout<<"損失"<<bet<<"元!"<<endl;
- total-=bet;
- }
- system("pause");
- system("cls");
- n++;
- goto re;
- end:
- if(total>0)
- {
- cout<<"\n恭喜您,贏了"<<total<<"元!\n"<<endl;
- }
- else if(total<0)
- {
- cout<<"\n不好意思,讓您損失了"<<-total<<"元!\n"<<endl;
- }
- else
- {
- cout<<"\n不輸不贏,全身而退!\n"<<endl;
- }
- cout<<"謝謝光臨,下次再來!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |