Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. inline void printMoneyFormat(float);
  5. inline int getRandomValue(int, int);
  6.  
  7. float gameHighLow(float);
  8.  
  9. inline float getPlayerBet(float);
  10. inline char getRangeHL();
  11. inline bool getResultHL(float, int);
  12.  
  13. int main ()
  14. {
  15. float playerMoney;
  16.  
  17. bool isExit = false;
  18.  
  19. srand(time(0));
  20.  
  21. int wybor;
  22.  
  23. printf("How much money do you have: ");
  24. scanf("%f", &playerMoney);
  25.  
  26. clearScreen();
  27.  
  28. do
  29. {
  30. printf("Remaining money: ");
  31. printMoneyFormat(playerMoney);
  32.  
  33. printf("Menu: \n 1) H/L \n 2) Wyjscie \n");
  34. scanf("%d", &wybor);
  35. fflush(stdin);
  36.  
  37. switch(wybor)
  38. {
  39. case 1:
  40. playerMoney = playerMoney + gameHighLow(playerMoney);
  41. break;
  42.  
  43. case 2:
  44. isExit = true;
  45. break;
  46.  
  47. default:
  48. printf("Error, check input. \n");
  49. }
  50.  
  51. }while(!isExit);
  52.  
  53. printf("Exit. \n");
  54.  
  55. return 0;
  56. }
  57.  
  58. void printMoneyFormat(float money)
  59. {
  60. printf("%.2f PLN \n", money);
  61. }
  62.  
  63. void clearScreen()
  64. {
  65. system("cls");
  66. }
  67.  
  68. int getRandomValue(int low, int high)
  69. {
  70. return (rand() % high) + low;
  71. }
  72.  
  73. float gameHighLow(float playerMoney)
  74. {
  75. clearScreen();
  76.  
  77. int rollValue;
  78. float playerBet;
  79. char playerRangePick;
  80.  
  81. float winnings = 0.0;
  82.  
  83. playerBet = getPlayerBet(playerMoney);
  84. playerRangePick = getRangeHL();
  85.  
  86. printf("Bet value: ");
  87. printMoneyFormat(playerBet);
  88. printf("Chosen range: %c \n \n", playerRangePick);
  89.  
  90. rollValue = getRandomValue(1, 6);
  91.  
  92. printf("Roll value: %d \n \n", rollValue);
  93.  
  94. if(getResultHL(playerRangePick, rollValue) == true)
  95. {
  96. winnings = playerBet * 0.8;
  97. }
  98. else
  99. {
  100. winnings = -playerBet;
  101. }
  102.  
  103. return winnings;
  104. }
  105.  
  106.  
  107. float getPlayerBet(float playerMoney)
  108. {
  109. float playerBet;
  110. do
  111. {
  112. printf("How much do you want to bet: ");
  113.  
  114. scanf("%f", &playerBet);
  115. fflush(stdin);
  116.  
  117. clearScreen();
  118.  
  119. if(playerBet > playerMoney)
  120. {
  121. printf("Error, not enough money.");
  122. }
  123.  
  124. }while(playerBet > playerMoney);
  125.  
  126. return playerBet;
  127. }
  128.  
  129. char getRangeHL()
  130. {
  131. char playerRangePick;
  132.  
  133. do
  134. {
  135. printf("Choose range [H/L] : ");
  136. scanf("%c", &playerRangePick);
  137.  
  138. }while(playerRangePick != 'h' && playerRangePick != 'l');
  139.  
  140. return playerRangePick;
  141. }
  142.  
  143. bool getResultHL(float playerRangePick, int rollValue)
  144. {
  145. if (playerRangePick == 'h')
  146. {
  147. if(rollValue > 3)
  148. {
  149. return true;
  150. }
  151. else
  152. {
  153. return false;
  154. }
  155. }
  156. else
  157. {
  158. if(rollValue <= 3)
  159. {
  160. return true;
  161. }
  162. else
  163. {
  164. return false;
  165. }
  166.  
  167. }
  168.  
  169. return false;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement