Advertisement
Guest User

Untitled

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