本帖最後由 鄭楀諺 於 2018-5-26 12:41 編輯
- #include<iostream>
- #include<cstdlib>
- #include<time.h>
- using namespace std;
- int main()
- {
- int random=0,round=1;
- int money=0,ans=0,bet=0,newmoney=0,exit=0;
- srand(time(NULL));
- while(true)
- {
- bool in=true;
- int numh=0,numh1=0,numh2=0,numh3=0,numh4=0;
- int h1=0,h2=0,h3=0,h4=0;
- while(in)
- {
- cout<<"第"<<round<<"局"<<endl;
- cout<<"「好事成雙」賽馬場"<<endl;
- cout<<"|-------------------------------------------------------------------------|終點"<<endl;
- cout<<"◆"<<endl;
- cout<<"★"<<endl;
- cout<<"▲"<<endl;
- cout<<"●"<<endl;
- cout<<"可用餘額"<<money<<"元"<<endl;
- cout<<"(1)買入 (2)下注 (3)離開 請選擇:";
- cin>>ans;
- if(ans==1)
- {
- cout<<"買入:";
- cin>>newmoney;
- if(newmoney<=0)
- {
- cout<<"輸入錯誤!"<<endl;
- _sleep(500);
- }
- else
- {
- money=money+newmoney;
- }
- }
- if(ans==2)
- {
- cout<<"下注:";
- cin>>bet;
- if(bet<=0)
- {
- cout<<"輸入錯誤!";
- _sleep(500);
- }
- if(bet>money)
- {
- cout<<"餘額不足!";
- _sleep(500);
- }
- else
- {
- in=false;
- cout<<"(1) ◆"<<endl;
- cout<<"(2) ★"<<endl;
- cout<<"(3) ▲"<<endl;
- cout<<"(4) ●"<<endl;
- cout<<"請輸入下注馬匹代碼:"<<endl;
- cin>>numh;
- if(numh==1)
- {
- numh1++;
- }
- if(numh==2)
- {
- numh2++;
- }
- if(numh==3)
- {
- numh3++;
- }
- if(numh==4)
- {
- numh4++;
- }
- if(numh>4)
- {
- cout<<"餘額不足!";
- _sleep(500);
- }
- }
- }
- if(ans==3)
- {
- cout<<"謝謝光臨,下次再會"<<endl;
- in=false;
- exit=1;
- _sleep(500);
- }
- if(ans>3)
- {
- cout<<"輸入錯誤!";
- _sleep(500);
- }
- system("cls");
- }
- if(exit!=0)
- {
- break;
- }
- while(h1!=75&&h2!=75&&h3!=75&&h4!=75)
- {
- random=rand()%4;
- if(random==0)
- {
- h1++;
- }
- if(random==1)
- {
- h2++;
- }
- if(random==2)
- {
- h3++;
- }
- if(random==3)
- {
- h4++;
- }
- cout<<"比賽進行中"<<endl;
- cout<<"|-------------------------------------------------------------------------|終點"<<endl;
- for(int i=0;i<=h1;i++)
- {
- cout<<" ";
- }
- cout<<"◆"<<endl;
- for(int i=0;i<=h2;i++)
- {
- cout<<" ";
- }
- cout<<"★"<<endl;
- for(int i=0;i<=h3;i++)
- {
- cout<<" ";
- }
- cout<<"▲"<<endl;
- for(int i=0;i<=h4;i++)
- {
- cout<<" ";
- }
- cout<<"●"<<endl;
- system("cls");
- }
- round++;
- system("cls");
- cout<<"比賽結束! 由";
- if(h1==75)
- {
- cout<<"◆搶先得馳"<<endl;
- numh1++;
- }
- if(h2==75)
- {
- cout<<"★搶先得馳"<<endl;
- numh2++;
- }
- if(h3==75)
- {
- cout<<"▲搶先得馳"<<endl;
- numh3++;
- }
- if(h4==75)
- {
- cout<<"●搶先得馳"<<endl;
- numh4++;
- }
- if(numh1==2)
- {
- cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
- money=money+bet;
- }
- else if(numh2==2)
- {
- cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
- money=money+bet;
- }
- else if(numh3==2)
- {
- cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
- money=money+bet;
- }
- else if(numh4==2)
- {
- cout<<"恭喜您!您賺了"<<bet<<"元!"<<endl;
- money=money+bet;
- }
- else
- {
- cout<<"唉!今天運氣不好啊!一不小心就虧了"<<bet<<"元!"<<endl;
- money=money-bet;
- }
- }
- return 0;
- }
複製代碼 |