Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- inline void printMoneyFormat(float);
- inline int getRandomValue(int, int);
- float gameHighLow(float);
- inline float getPlayerBet(float);
- inline char getRangeHL();
- inline bool getResultHL(float, int);
- int main ()
- {
- float playerMoney;
- bool isExit = false;
- srand(time(0));
- int wybor;
- printf("How much money do you have: ");
- scanf("%f", &playerMoney);
- clearScreen();
- do
- {
- printf("Remaining money: ");
- printMoneyFormat(playerMoney);
- printf("Menu: \n 1) H/L \n 2) Wyjscie \n");
- scanf("%d", &wybor);
- fflush(stdin);
- switch(wybor)
- {
- case 1:
- playerMoney = playerMoney + gameHighLow(playerMoney);
- break;
- case 2:
- isExit = true;
- break;
- default:
- printf("Error, check input. \n");
- }
- }while(!isExit);
- printf("Exit. \n");
- return 0;
- }
- void printMoneyFormat(float money)
- {
- printf("%.2f PLN \n", money);
- }
- void clearScreen()
- {
- system("cls");
- }
- int getRandomValue(int low, int high)
- {
- return (rand() % high) + low;
- }
- float gameHighLow(float playerMoney)
- {
- clearScreen();
- int rollValue;
- float playerBet;
- char playerRangePick;
- float winnings = 0.0;
- playerBet = getPlayerBet(playerMoney);
- playerRangePick = getRangeHL();
- printf("Bet value: ");
- printMoneyFormat(playerBet);
- printf("Chosen range: %c \n \n", playerRangePick);
- rollValue = getRandomValue(1, 6);
- printf("Roll value: %d \n \n", rollValue);
- if(getResultHL(playerRangePick, rollValue) == true)
- {
- winnings = playerBet * 0.8;
- }
- else
- {
- winnings = -playerBet;
- }
- return winnings;
- }
- float getPlayerBet(float playerMoney)
- {
- float playerBet;
- do
- {
- printf("How much do you want to bet: ");
- scanf("%f", &playerBet);
- fflush(stdin);
- clearScreen();
- if(playerBet > playerMoney)
- {
- printf("Error, not enough money.");
- }
- }while(playerBet > playerMoney);
- return playerBet;
- }
- char getRangeHL()
- {
- char playerRangePick;
- do
- {
- printf("Choose range [H/L] : ");
- scanf("%c", &playerRangePick);
- }while(playerRangePick != 'h' && playerRangePick != 'l');
- return playerRangePick;
- }
- bool getResultHL(float playerRangePick, int rollValue)
- {
- if (playerRangePick == 'h')
- {
- if(rollValue > 3)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- if(rollValue <= 3)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement