Skip to content

Instantly share code, notes, and snippets.

@BMAGS6
Created July 13, 2024 07:09
Show Gist options
  • Save BMAGS6/6c34a148ca0be0f919f7eb48576d792a to your computer and use it in GitHub Desktop.
Save BMAGS6/6c34a148ca0be0f919f7eb48576d792a to your computer and use it in GitHub Desktop.
Small Roulette Program -- Windows Specific
/*******************************************************************************
Roulette 1.5.1 -- MADE BY BMAGS -- Windows-Specific
*******************************************************************************/
#include <stdlib.h> /* For rand(), srand(), and exit() */
#include <stdio.h> /* For scanf(), printf(), and puts() */
#include <time.h> /* For time(); used to seed rand() */
#include <windows.h>/* For using UTF-8 encoding (box-drawing characters and emojis specifically) */
/** Function Prototypes: **/
void straightBet (int bet, float money, float wager); /* Straight Bet */
void brokeChecker (float money); /* Check for positive balance */
void betsList (void); /* List of Bets */
void mainMenu (float money); /* Main Menu */
void bettingMenu (float money); /* Bet/Wager Menu */
void quitSelection (float money); /* Quit Menu */
void topLineBet (float money, float wager); /* Top Line Bet */
void firstColumnBet (float money, float wager); /* 1st Column Bet */
void secondColumnBet (float money, float wager); /* 2nd Column Bet */
void thirdColumnBet (float money, float wager); /* 3rd Column Bet */
void lowHalfBet (float money, float wager); /* Low Half Bet */
void highHalfBet (float money, float wager); /* High Half Bet */
void blackBet (float money, float wager); /* BLACK Bet */
void redBet (float money, float wager); /* RED Bet */
void evenBet (float money, float wager); /* EVEN Bet */
void oddBet (float money, float wager); /* ODD Bet */
void firstDozenBet (float money, float wager); /* 1st Dozen Bet */
void secondDozenBet (float money, float wager); /* 2nd Dozen Bet */
void thirdDozenBet (float money, float wager); /* 3rd Dozen Bet */
void rowBet (float money, float wager); /* Row Bet */
void snakeBet (float money, float wager); /* Zig-Zag Bet */
void showStatistics (void); /* Show Game Statistics */
void handleWinningBet(float money, float wager, float multiplier, int result, const char *message); /* Handle winning bets */
void handleLosingBet (float money, float wager, int result, const char* message); /* Handle losing bets */
int main (void); /* Entry Point */
/** Slot Structure: **/
typedef struct Pocket
{
char half; /* 'l' Low half, 'h' High, 'z' 0/00 */
char parity; /* 'e' Even, 'o' Odd, 'z' 0/00 */
char color; /* 'b' Black, 'r' Red, 'g' Green */
char dozen; /* 'f' 1st, 's' 2nd, 't' 3rd, 'z' 0/00 */
char column; /* 'f' 1st, 's' 2nd, 't' 3rd, 'z' 0/00 */
char snake; /* 'y' if in zig-zag pattern, 'n' if not */
}Pocket;
/** Global Statistics Variables: **/
float totalSessionWinnings = 0; /* Money earned in session */
float totalRoundWinnings = 0; /* Money earned in round */
int totalRoundsPlayed = 1; /* Number of rounds played in session */
int totalBetsPlaced = 0; /* Bets placed in session */
int betsPlacedThisRound = 0; /* Bets placed in round */
int betsWonThisRound = 0; /* Bets won in round */
int betsLostThisRound = 0; /* Bets lost in round */
int betsWonThisSession = 0; /* Bets won in session */
int betsLostThisSession = 0; /* Bets lost in session */
/** Array of Pocket-type structures for the wheel: **/
Pocket wheel[38] =
{
{'z', 'z', 'g', 'z', 'z', 'n'}, /* 0 */
{'l', 'o', 'b', 'f', 'f', 'y'}, /* 1 */
{'l', 'e', 'r', 'f', 's', 'n'}, /* 2 */
{'l', 'o', 'b', 'f', 't', 'n'}, /* 3 */
{'l', 'e', 'r', 'f', 'f', 'n'}, /* 4 */
{'l', 'o', 'r', 'f', 's', 'y'}, /* 5 */
{'l', 'e', 'r', 'f', 't', 'n'}, /* 6 */
{'l', 'o', 'r', 'f', 'f', 'n'}, /* 7 */
{'l', 'e', 'r', 'f', 's', 'n'}, /* 8 */
{'l', 'o', 'r', 'f', 't', 'y'}, /* 9 */
{'l', 'e', 'b', 'f', 'f', 'n'}, /* 10 */
{'l', 'o', 'b', 'f', 's', 'n'}, /* 11 */
{'l', 'e', 'r', 'f', 't', 'y'}, /* 12 */
{'l', 'o', 'b', 's', 'f', 'n'}, /* 13 */
{'l', 'e', 'r', 's', 's', 'y'}, /* 14 */
{'l', 'o', 'b', 's', 't', 'n'}, /* 15 */
{'l', 'e', 'r', 's', 'f', 'y'}, /* 16 */
{'l', 'o', 'b', 's', 's', 'n'}, /* 17 */
{'l', 'e', 'r', 's', 't', 'n'}, /* 18 */
{'h', 'o', 'r', 's', 'f', 'y'}, /* 19 */
{'h', 'e', 'b', 's', 'f', 'n'}, /* 20 */
{'h', 'o', 'r', 's', 's', 'n'}, /* 21 */
{'h', 'e', 'b', 's', 't', 'n'}, /* 22 */
{'h', 'o', 'r', 's', 'f', 'y'}, /* 23 */
{'h', 'e', 'b', 's', 's', 'n'}, /* 24 */
{'h', 'o', 'r', 'f', 't', 'n'}, /* 25 */
{'h', 'e', 'b', 't', 'f', 'n'}, /* 26 */
{'h', 'o', 'r', 't', 's', 'y'}, /* 27 */
{'h', 'e', 'b', 't', 't', 'n'}, /* 28 */
{'h', 'o', 'b', 't', 'f', 'n'}, /* 29 */
{'h', 'e', 'r', 't', 's', 'y'}, /* 30 */
{'h', 'o', 'b', 't', 't', 'n'}, /* 31 */
{'h', 'e', 'r', 't', 'f', 'y'}, /* 32 */
{'h', 'o', 'b', 't', 's', 'n'}, /* 33 */
{'h', 'e', 'r', 't', 't', 'y'}, /* 34 */
{'h', 'o', 'b', 't', 'f', 'n'}, /* 35 */
{'h', 'e', 'r', 't', 's', 'n'}, /* 36 */
{'z', 'z', 'g', 'z', 'z', 'n'} /* 00 */
};
/** Number Generator: **/
int numberGenerator(void)
{
int result = (rand() % 37) + 1; /* Pick a number from 0-38 */
return result;
}
/** Bets List Function: **/
void betsList(void)
{
puts("╔════════════════╗\n"
"β•‘ Enter your bet β•‘\n"
"β•Ÿβ”€β”€β”€β”€β”€β”€β•₯β”€β”€β”€β”€β”€β”€β”€β”€β”€β•œ ╔═════════╗\n"
"β•‘Bets: β•‘ β•‘Payout: β•‘\n"
"╠══════╩══════════════════════════════════════════════════════╬═════════╣\n"
"β•‘0-36 β”‚35 to 1 β•‘\n"
"β•‘37. 00 β”‚35 to 1 β•‘\n"
"β•‘38. Top Line (00, 0, 1, 2, and 3) β”‚6 to 1 β•‘\n"
"β•‘39. 1st column (1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34) β”‚2 to 1 β•‘\n"
"β•‘40. 2nd column (2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35) β”‚2 to 1 β•‘\n"
"β•‘41. 3rd column (3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36) β”‚2 to 1 β•‘\n"
"β•‘42. Low Half β”‚1 to 1 β•‘\n"
"β•‘43. High Half β”‚1 to 1 β•‘\n"
"β•‘44. BLACK β”‚1 to 1 β•‘\n"
"β•‘45. RED β”‚1 to 1 β•‘\n"
"β•‘46. EVENS β”‚1 to 1 β•‘\n"
"β•‘47. ODDS β”‚1 to 1 β•‘\n"
"β•‘48. 1st Dozen (1-12) β”‚2 to 1 β•‘\n"
"β•‘49. 2nd Dozen (13-24) β”‚2 to 1 β•‘\n"
"β•‘50. 3rd Dozen (25-36) β”‚2 to 1 β•‘\n"
"β•‘51. Row (0, 00) β”‚17 to 1 β•‘\n"
"β•‘52. Snake (1, 5, 9, 12, 14, 16, 19, 23, 27, 30, 32, 34) β”‚2 to 1 β•‘\n"
"β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•\n");
return;
}
/** Main Menu Function: **/
void mainMenu(float money)
{
char menuSelection;
puts ("╔════════════════════════╗\n"
"β•‘* * * ROULETTE! * * *β•‘\n"
"β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•\n\n");
printf("Money πŸ’° : $%.2f\n\n", money);
puts ("Menu:\n"
"1. Place Bet πŸ’°\n"
"2. Show Statistics πŸ“ˆ\n"
"3. Quit πŸšͺ\n");
retrySelection:
puts ("\nEnter a selection:\n");
scanf(" %c", &menuSelection);
switch (menuSelection)
{
case '1': brokeChecker(money);
bettingMenu(money);
break;
case '2': puts("Statistics:\n\n");
showStatistics();
mainMenu(money);
break;
case '3': puts("Don't let the house beat you! Come Again Soon!\n");
exit(0);
default: puts("\nERROR ❌: Invalid selection. Try again\n");
goto retrySelection;
}
}
/** Betting Menu: **/
void bettingMenu(float money)
{
int betSelection;
float wager;
redoWager: /* Label if user over-bets: */
puts("\nEnter your wager:\n");
scanf("%f", &wager);
if (wager > money) /* Check if the user over-bets: */
{
printf("\nERROR ❌: You only have $%.2f, you cannot bet $%.2f!\n", money, wager);
wager = 0;
goto redoWager;
}
else if (wager < 0.01) /* Check if the user bets too little: */
{
printf("\nERROR ❌: You cannot bet $%.2f!\n", wager);
wager = 0;
goto redoWager;
}
else
{
retryBetSelection:
betsList(); /* Display the list of bets a player can make */
scanf("%d", &betSelection);
totalBetsPlaced += 1;
betsPlacedThisRound += 1;
if (betSelection >= 0 && betSelection <= 36) /* Check for a straight bet */
{
printf("\nYou've chosen to wager $%.2f on %d!\n", wager, betSelection);
straightBet(betSelection, money, wager);
}
else
{
switch (betSelection)
{
/* 00: */
case 37: printf("\nYou've chosen to wager $%.2f on 00!\n", wager);
straightBet(betSelection, money, wager);
break;
/* Top Line Bet: */
case 38: printf("You've chosen to wager $%.2f on a Top Line bet!\n", wager);
topLineBet(money, wager);
break;
/* 1st Column: */
case 39: printf("You've chosen to wager $%.2f on the 1st Column!\n", wager);
firstColumnBet(money, wager);
break;
/* 2nd Column: */
case 40: printf("You've chosen to wager $%.2f on the 2nd Column!\n", wager);
secondColumnBet(money, wager);
break;
/* 3rd Column: */
case 41: printf("You've chosen to wager $%.2f on the 3rd Column!\n", wager);
thirdColumnBet(money, wager);
break;
/* Low Half: */
case 42: printf("You've chosen to wager $%.2f on the Low Half!\n", wager);
lowHalfBet(money, wager);
break;
/* High Half: */
case 43: printf("You've chosen to wager $%.2f on the High Half!\n", wager);
highHalfBet(money, wager);
break;
/* BLACK: */
case 44: printf("You've chosen to wager $%.2f on ⚫ BLACK!\n", wager);
blackBet(money, wager);
break;
/* RED: */
case 45: printf("You've chosen to wager $%.2f on πŸ”΄ RED!\n", wager);
redBet(money, wager);
break;
/* EVENS: */
case 46: printf("You've chosen to wager $%.2f on the Evens!\n", wager);
evenBet(money, wager);
break;
/* ODDS: */
case 47: printf("You've chosen to wager $%.2f on the Odds!\n", wager);
oddBet(money, wager);
break;
/* 1st Dozen: */
case 48: printf("You've chosen to wager $%.2f on the 1st Dozen!\n", wager);
firstDozenBet(money, wager);
break;
/* 2nd Dozen: */
case 49: printf("You've chosen to wager $%.2f on the 2nd Dozen!\n", wager);
secondDozenBet(money, wager);
break;
/* 3rd Dozen: */
case 50: printf("You've chosen to wager $%.2f on the 3rd Dozen!\n", wager);
thirdDozenBet(money, wager);
break;
/* Row (00,0): */
case 51: printf("You've chosen to wager $%.2f on the Row!\n", wager);
rowBet(money, wager);
break;
/* Snake: */
case 52: printf("You've chosen to wager $%.2f on the snake! 🐍\n", wager);
snakeBet(money, wager);
break;
default: puts("\nERROR: Invalid Entry. TRY AGAIN");
goto retryBetSelection;
}
}
}
}
/** Straight Bet Function: **/
void straightBet(int bet, float money, float wager)
{
int result = numberGenerator();
if (result == bet && bet == 37) /* Check for a winning 00 */
{
handleWinningBet(money, wager, 36, result, "WINNER! πŸ’°πŸŽ‰ 00 HIT! You won $%.2f!\n");
}
else if (result == bet) /* Check for a winner */
{
handleWinningBet(money, wager, 36, result,
"WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, taking your balance to $%.2f!\n");
}
else if (result != bet && bet == 37) /* Check for a losing 00 */
{
handleLosingBet(money, wager, result,
"\nLOSER! πŸ•± The ball landed in pocket #%d! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
else /* Check for a loser */
{
handleLosingBet(money, wager, result,
"\nLOSER! πŸ•± The ball landed in pocket #%d! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
return;
}
/** Top Line Function: **/
void topLineBet(float money, float wager)
{
int result = numberGenerator();
if (result == 37 || (result >= 0 && result <= 3))
{
handleWinningBet(money, wager, 7, result, result == 37 ? "WINNER! πŸ’°πŸŽ‰ 00 HIT! You won $%.2f!\n" : "WINNER! %d HIT! You won $%.2f!\n");
}
else
{
handleLosingBet(money, wager, result,
"\nLOSER! πŸ•± The ball landed in pocket #%d, not in the top line! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** 1st Column Function: **/
void firstColumnBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].column == 'f') /* Check for winner: */
{
handleWinningBet(money, wager, 3, result,
"WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, in the 1st column, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 3,
"\nLOSER! πŸ•± The ball landed in pocket #%d. You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** 2nd Column Function: **/
void secondColumnBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].column == 's') /* Check for winner: */
{
handleWinningBet(money, wager, 3, result,
"WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, in the 2nd column, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 3,
"\nLOSER! πŸ•± The ball landed in pocket #%d. You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** 3rd Column Function: **/
void thirdColumnBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].column == 't') /* Check for winner: */
{
handleWinningBet(money, wager, 3, result,
"WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, in the 3rd column, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 3,
"\nLOSER! πŸ•± The ball landed in pocket #%d. You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** Low Half Function: **/
void lowHalfBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].half == 'l') /* Check for winner: */
{
handleWinningBet(money, wager, 2, result,
"WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, in the first half, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 2,
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the higher half! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** High Half Function: **/
void highHalfBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].half == 'h') /* Check for winner: */
{
handleWinningBet(money, wager, 2, result,
"WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, in the first half, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 2,
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the lower half! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** BLACK Function: **/
void blackBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].color == 'b') /* Check for winner: */
{
handleWinningBet(money, wager, 2, result, "WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, ⚫ BLACK, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 2,
"\nLOSER! πŸ•± The ball landed in pocket #%d, πŸ”΄ RED! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** RED Function: **/
void redBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].color == 'r') /* Check for winner: */
{
handleWinningBet(money, wager, 2, result, "WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, πŸ”΄ RED, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 2,
"\nLOSER! πŸ•± The ball landed in pocket #%d, ⚫ BLACK! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** EVENS Function: **/
void evenBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].parity == 'e') /* Check for winner: */
{
handleWinningBet(money, wager, 2, result, "WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 2,
"\nLOSER! πŸ•± The ball landed in pocket #%d, ODD! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** ODDS Function: **/
void oddBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].parity == 'o') /* Check for winner: */
{
handleWinningBet(money, wager, 2, result, "WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, 2,
"\nLOSER! πŸ•± The ball landed in pocket #%d, EVEN! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** 1st Dozen Function: **/
void firstDozenBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].dozen == 'f') /* Check for winner: */
{
handleWinningBet(money, wager, 3, result, "WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, result, wheel[result].dozen == 's' ?
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the 2nd Dozen! You lose your wager of $%.2f,\n taking your balance down to $%.2f!\n\n":
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the 3rd Dozen! You lose your wager of $%.2f,\n taking your balance down to $%.2f!\n\n");
}
}
/** 2nd Dozen Function: **/
void secondDozenBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].dozen == 's') /* Check for winner: */
{
handleWinningBet(money, wager, 3, result, "WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, result, wheel[result].dozen == 'f' ?
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the 1st Dozen! You lose your wager of $%.2f,\n taking your balance down to $%.2f!\n\n":
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the 3rd Dozen! You lose your wager of $%.2f,\n taking your balance down to $%.2f!\n\n");
}
}
/** 3rd Dozen Function: **/
void thirdDozenBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].dozen == 't') /* Check for winner: */
{
handleWinningBet(money, wager, 3, result, "WINNER! πŸ’°πŸŽ‰ The ball landed in pocket #%d, taking your balance to $%.2f!\n");
}
else
{
handleLosingBet(money, wager, result, wheel[result].dozen == 's' ?
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the 2nd Dozen! You lose your wager of $%.2f,\n taking your balance down to $%.2f!\n\n":
"\nLOSER! πŸ•± The ball landed in pocket #%d, in the 1st Dozen! You lose your wager of $%.2f,\n taking your balance down to $%.2f!\n\n");
}
}
/** Row Function: **/
void rowBet(float money, float wager)
{
int result = numberGenerator();
if ((result == 0) || (result == 37)) /* Check for winning 0/00: */
{
handleWinningBet(money, wager, 18, result, result == 0 ?
"WINNER! πŸ’°πŸŽ‰ 0 hit! at a payout of 17 to 1, you won $%.2f!\n\n":
"WINNER! πŸ’°πŸŽ‰ 0 hit! at a payout of 17 to 1, you won $%.2f!\n\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, result,
"\nLOSER! πŸ•± The ball landed in pocket #%d! You lose your wager of $%.2f, taking your balance down to $%.2f!\n\n");
}
}
/** Snake Bet: **/
void snakeBet(float money, float wager)
{
int result = numberGenerator();
if (wheel[result].snake == 'y') /* Check for winner: */
{
handleWinningBet(money, wager, 3, result, "WINNER! πŸπŸ’°πŸŽ‰ The ball landed in pocket #%d, taking your balance to $%.2f!\n");
}
else /* Check for loser: */
{
handleLosingBet(money, wager, result,
"\nLOSER! πŸ•± The ball landed in pocket #%d, not in the snake! You lose your wager of $%.2f,\n taking your balance down to $%.2f!\n\n");
}
}
/** Quit Option: **/
void quitSelection(float money)
{
/* Check if user is broke: */
brokeChecker(money);
/* IF user is not broke: */
printf("Keep Going?\n('Y' for yes, anything else to quit):\n");
char quitChoice;
scanf(" %c", &quitChoice);
if (quitChoice == 'y' || quitChoice == 'Y')
{
puts("THAT'S THE SPIRIT!\n\n");
mainMenu(money);
}
else
{
puts("You miss 100% of the shots you don't take! Don't forget to take a shot at the wheel soon!\n");
exit(0);
}
}
/** Statistics Display Function: **/
void showStatistics(void)
{
printf("Total Rounds Played: %d\n"
"Total Bets Placed: %d\n"
"Total Round Winnings: $%.2f\n"
"Total Session Winnings: $%.2f\n"
"Bets Won This Round: %d\n"
"Bets Lost This Round: %d\n"
"Bets Won This Session: %d\n"
"Bets Lost This Session: %d\n"
"Bets Placed This Round: %d\n\n",
totalRoundsPlayed,
totalBetsPlaced,
totalRoundWinnings,
totalSessionWinnings,
betsWonThisRound,
betsLostThisRound,
betsWonThisSession,
betsLostThisSession,
betsPlacedThisRound);
return;
}
/** Broke Checker: **/
void brokeChecker(float money)
{
if (money < 0.01)
{
printf("\nYou are BROKE! Restart program? ('y' for yes, anything else to quit)\n");
char restartChoice;
scanf(" %c", &restartChoice);
if (restartChoice == 'y' || restartChoice == 'Y')
{
puts("RESTARTING PROGRAM...");
betsWonThisRound = 0;
totalRoundsPlayed += 1;
betsLostThisRound = 0;
totalRoundWinnings = 0;
betsPlacedThisRound = 0;
main();
}
else
{
puts("\n90% of Gamblers quit right before they hit big! Come again soon!\n");
exit(0);
}
}
else
{
return;
}
}
/** Handle Winning Bets: **/
void handleWinningBet(float money, float wager, float multiplier, int result, const char* message)
{
float winnings = wager * multiplier;
if (multiplier == 2)
{
money = (money - wager) + winnings;
}
else
{
money += winnings;
}
totalRoundWinnings += winnings;
totalSessionWinnings += winnings;
betsWonThisRound += 1;
betsWonThisSession += 1;
printf(message, result, winnings);
quitSelection(money);
}
/** Handle Losing Bets: **/
void handleLosingBet(float money, float wager, int result, const char *message)
{
money -= wager;
betsLostThisRound += 1;
betsLostThisSession += 1;
printf(message, result, wager, money);
quitSelection(money);
}
/** Entry Point: **/
int main(void)
{
float startingCash = 100.00; /* Can be any floating point value */
srand(time(NULL)); /* Seed the number generator */
SetConsoleOutputCP(CP_UTF8); /* Enable UTF-8 to use emojis and box-drawing characters */
mainMenu(startingCash);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment