Roulette Game
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define minv 0
#define maxv 36
void showInstructions();
void makeBet(float *betType, float *selection);
void getBetAmount(float *betAmount);
void spinWheel(int *number);
float figureWinnings(int number, int selection, int betType, float betAmount);
int main()
{
// all the variables
int number;
float betType, selection, getBA, spinW, betAmount, n, fW;
// show the instructions
showInstructions();
//address of betType and selection is passed
makeBet(&betType, &selection);
// address of betAmount is passed
getBetAmount(&betAmount);
//address of number is passed is passed
spinWheel(&number);
// winnings is calculated
fW += figureWinnings(number, selection, betType, betAmount);
return 0;
}
// prints the instructions
void showInstructions()
{
printf("***The Roulette Game***");
printf("\n\n Instructions: ");
printf("\n\n The roulette wheel has the numbers 0-36 on it.\n You can place your bet in one of three ways: ");
printf("\n\t 1. Bet on a number (payout is 36 times the bet amount)");
printf("\n\t 2. Bet on odd or even (payout is 2 times the bet)");
printf("\n\t 3. Bet on a dozen ~ first 1-12, second 13-24, third 25-36 (payout is 3 times the bet)");
printf("\n The number zero does not count for odd or even or dozen, but can count as a number bet.");
}
// (*betType != 1 || *betType != 2 || *betType !=3) says that if any of the bet is in 1 2 or 3 pass else the value entered is incorrect
void makeBet(float *betType, float *selection)
{
printf("\n\n What type of bet would you like to make?\n\t1-number\n\t2-even/odd\n\t3-dozen\n\t");
scanf("\n%f",betType);
while ((*betType != 1 || *betType != 2 || *betType !=3))
{
printf("\nIncorrect. Please try again!\n\t");
makeBet(betType,selection);
}
if (*betType == 1)
{
printf("Which number in the range 0-36 are you betting on?\n\t");
scanf("\n%f",selection);
while (*selection < minv || *selection > maxv)
{
printf("Invalid! Try again. Choose a number in the range 0-36\n");
scanf("\n%f",selection);
}
}
else if (*betType == 2)
{
printf("Odd or even? \n\t1-Odd \n\t2-Even\n\t");
scanf("\n%f", selection);
while (*selection != 1 && *selection != 2)
{
printf("Try again!\n");
scanf("\n%f",selection);
}
}
else if (*betType == 3)
{
printf("Which dozen are you betting on? \n\t1 (1-12) \n\t2 (13-24) \n\t3 (25-36)\n\t");
scanf("\n%f",selection);
while (*selection != 1 && *selection != 2 && *selection != 3)
{
printf("Try again!");
scanf("\n%f",selection);
}
}
}
// gets the amount you want to bet
void getBetAmount(float *betAmount)
{
printf("\nHow much $ would you like to bet?\n\t");
scanf(" %f",betAmount);
}
// get a random int number in the range 0-36 here you need to use *number to take in the value
void spinWheel(int *number)
{
srand(time(0)); // ensures different random number is generated every time program is run
int lower=0, higher=36;
*number= ((rand()%(higher - lower + 1))+lower );
printf("\nThe number is %d", *number);
}
// calculate the winnings here you need to use winnings =-betAmount if lost
float figureWinnings(int number, int selection, int betType, float betAmount)
{
float winnings=0;
if (betType == 1)
{
if (selection == number) winnings = betAmount * 36;
else
winnings = -betAmount;
}
else if (betType == 2)
{
if (selection == 1)
{
if (number % 2 == 1)
winnings = betAmount * 2;
else
winnings = -betAmount;
}
else if (selection == 2)
{
if (number % 2 == 0)
winnings = betAmount * 2;
else
winnings = -betAmount;
}
}
else if (betType == 3)
{
// calculate wins and losses
if (selection == 1)
{
if (number >= 1 && number <= 12)winnings = betAmount * 3;
else
winnings = -betAmount;
}
else if (selection == 2)
{
if (number >= 13 && number <= 24)winnings = betAmount * 3;
else
winnings = -betAmount;
}
else if (selection == 3)
{
if (number >= 25 && number <= 36)winnings = betAmount * 3;
else
winnings = -betAmount;
}
}
printf("\nThe winnings are %f", winnings);
return winnings;
}