Board logo

標題: [作業] 賽馬程式 (六) [打印本頁]

作者: 鄭繼威    時間: 2023-3-4 20:28     標題: [作業] 賽馬程式 (六)

本帖最後由 葉桔良 於 2023-3-11 18:57 編輯

1. 比對比賽結果與玩家下注,判斷玩家贏了錢還是輸了錢
2. 對變數balance做加減,使可用餘額會隨著玩家輸贏而增減

規則如下:
若最後勝出的選手與玩家下注相同,玩家贏得下注金3倍的錢。
反之,玩家損失下注金。





  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, bet, player;
  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.         if(buyin<=0)
  27.         {
  28.              cout<<"輸入錯誤!";
  29.              _sleep(1500);
  30.              goto re;     
  31.         }
  32.         balance+=buyin;
  33.         goto re;         
  34.     }
  35.     else if(option==2)
  36.     {
  37.         cout<<"下注: ";
  38.         cin>>bet;
  39.         if(bet<=0)
  40.         {
  41.              cout<<"輸入錯誤!";
  42.              _sleep(1500);
  43.              goto re;     
  44.         }
  45.         if(bet>balance)
  46.         {
  47.              cout<<"可用餘額不足,請先買入!";
  48.              _sleep(1500);
  49.              goto re;     
  50.         }
  51.         cout<<endl<<"(1)◆ (2)★ (3)▲ (4)● 請選擇: ";
  52.         cin>>player;
  53.         cout<<"比賽即將開始..."<<endl<<endl;         
  54.     }
  55.     else if(option==3)
  56.     {
  57.         goto end;         
  58.     }
  59.     else
  60.     {
  61.         cout<<"輸入錯誤!";
  62.         _sleep(1500);
  63.         goto re;
  64.     }
  65.     system("pause");
  66.     system("cls");
  67.     while(s[r]<=73)
  68.     {
  69.         r=rand()%4;   //0~3
  70.         s[r]++;
  71.         cout<<"比賽進行中"<<endl;
  72.         cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  73.         for(int i=0; i<4; i++)
  74.         {
  75.             for(int j=0; j<s[i]; j++)
  76.                 cout<<" ";
  77.             cout<<p[i]<<endl;
  78.         }
  79.         _sleep(50);
  80.         system("cls");
  81.     }
  82.     cout<<"比賽結束!  由 "<<p[r]<<" 先馳得點!"<<endl;
  83.     cout<<"-------------------------------------------------------------------------| 終點"<<endl;
  84.     for(int i=0; i<4; i++)
  85.     {
  86.         for(int j=0; j<s[i]; j++)
  87.             cout<<" ";
  88.         cout<<p[i]<<endl;
  89.     }
  90.     system("pause");
  91.     n++;
  92.     goto re;
  93.     end:
  94.     cout<<endl<<"慢走!"<<endl;
  95.     _sleep(1500);
  96.     return 0;
  97. }
複製代碼
本帖隱藏的內容需要積分高於 1 才可瀏覽

作者: 陳昱州    時間: 2023-3-4 21:15

此帖僅作者可見
作者: 陳冠霖    時間: 2023-3-4 21:16

此帖僅作者可見
作者: 宥竣    時間: 2023-3-5 09:10

此帖僅作者可見
作者: 楊惇翔    時間: 2023-3-5 16:27

此帖僅作者可見
作者: 林哲弘    時間: 2023-3-11 09:34

此帖僅作者可見
作者: 吳柏融    時間: 2023-3-11 19:22

此帖僅作者可見
作者: 博勛    時間: 2023-3-11 19:30

此帖僅作者可見
作者: 王述勳    時間: 2023-3-11 19:31

此帖僅作者可見
作者: 盧禹丞    時間: 2023-3-11 19:31

此帖僅作者可見
作者: 黃兆駿    時間: 2023-3-11 19:33

此帖僅作者可見
作者: 葉晉維    時間: 2023-3-11 19:33

此帖僅作者可見
作者: 葉權諒    時間: 2023-3-11 19:33

此帖僅作者可見
作者: 張晏齊    時間: 2023-3-11 19:36

此帖僅作者可見
作者: 黃兆駿    時間: 2023-3-11 19:42

此帖僅作者可見
作者: 葉晉維    時間: 2023-3-11 19:48

此帖僅作者可見




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