In: Computer Science
"Gambling Greg" Assignment
Outcomes:
Program Specifications:
Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a structure name DOG as follows:
Name, amount to pay out if Greg wins, and the odds of this dog winning the race.
The program should have the following menu:
[G]amble
[R]esults of All Races
[L]eave the Dog Track
If Greg selects [G] the program will ask Greg for his wager and allow Greg to pick a dog from a list. The program will then run the race. The result will be shown to Greg. The results of the race will be stored for future use.
If Greg selects [R] the program will show Greg the results of all previous races entered during this run of the program.
If Greg selects [L] the program will end.
The dogs:
You will create 9 different dogs. See below:
Dog Name |
Payout |
Odds of Winning |
You name the dogs |
2 to 1 |
40% |
5 to 1 |
10% |
|
10 to 1 |
8% |
|
15 to 1 |
6% |
|
50 to 1 |
1% |
|
20 to 1 |
4% |
|
10 to 1 |
8% |
|
5 to 1 |
10% |
|
3 to 1 |
13% |
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU
NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR
YOU
// Declare the required header file
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
//Demonstrate the ability to create and use structs
// the name of DOG
// to store the information of dog
struct DOG
{
// The dog information which structure have
// Dog name
char Name[32];
// amount of pay of if Greg Wins
int amounttopayout;
// Odds of the dog winning the race
int Oddsofthewinningdog;
};
// Demonstrate the ability to create
//and use an array of structs
// array of struct use to store all the given
// DOg information
void arrayofstruct(struct DOG *d)
{
// Char Dog Name store the information of dog name
char DogNames[9][32] = {"Prince", "Dayna", "Rockey", "Tommy", "Beast", "Buddy", "Oscar", "Lovely", "Teddy"};
// Create an array of pay out to store the dog payout information
int Payout[9] = {2, 5, 10, 15, 50, 20, 10, 5, 3};
// Create an array of Odds winning dog % to store the dog percent
int Odds_of_Win_dog[9] = {40, 10, 8, 6, 1, 4, 8, 10, 13};
// loop to store the information
for (int i = 0; i < 9; i++)
{
strcpy(d[i].Name, DogNames[i]);
d[i].amounttopayout = Payout[i];
d[i].Oddsofthewinningdog = Odds_of_Win_dog[i];
}
}
//Demonstrate the ability to generate
// and use random numbers
// Create a function of random number to choose the
// random dof for the race
void randomnumbers(struct DOG *d, int *randomnum)
{
// Initially random r is equal to zero
int r = 0;
// Loop to compute the random
for (int i = 0; i < 9; i++)
{
// for loop to access the random dog
for (int j = 0; j < d[i].Oddsofthewinningdog; j++)
{
// increment the random
randomnum[r++] = i;
}
}
}
// Demonstrate the ability to create and use menus
// to display the following menu:
char menu()
{
// Display for Gamble
printf("[G]amble.\n");
// Display for Result
printf("[R]esult of all Races\n");
// Display for Leave te dog track
printf("[L]eave the Dog Track\n");
// Ask from the Greg to choice the dog
printf("Please select the choice Greg:");
char ch;
scanf(" %c", &ch);
// retur the choice
return ch;
}
// Create a function to pickup the dog list
void pickupdoglist(struct DOG *d)
{
// Display the Dog Table with all the name of Dog and
// all the information
printf("S.No. Dog name Payout Odds of Winning \n");
// For loop to display all the stored dog information
for (int i = 0; i < 9; i++)
{
printf("%d. %7s, %4d to 1, %7d%% \n", i + 1, d[i].Name, d[i].amounttopayout, d[i].Oddsofthewinningdog);
}
}
// Create a dog running race function
// to running the choice dog with randomly dog
int dogrunnningrace(int *randomnum)
{
// timer start with zero random
srand(time(0));
// Declare an random variable to store random
// number
int random = rand() % 100;
// Return the random number
return randomnum[random];
}
// Create a dog infromation function to ask from the
// Greg
void doginformation(struct DOG *d, int *randomnum, char *buffer)
{
// Ask from the Greg to input the wager for Dog
printf("Please Greg input a wager:");
int wager;
scanf("%d", &wager);
// Call the pickupdog list function
pickupdoglist(d);
// Greg to pick a dog from the list
printf("Please pick up a dog from the list by s.no.:");
int pick;
scanf("%d", &pick);
// Pickup dog index Initially with zero
pick = pick - 1;
// Call the dogrunning race function
int raceresult = dogrunnningrace(randomnum);
// Check the pickup dog is equal to race result
if (pick == raceresult)
{
// Display the result with the name of dog and wager
printf("%s wins the race. you won %d\n", d[pick].Name, wager * (d[pick].amounttopayout));
// Store the result for future use
sprintf(buffer, "%s wins the race. you won %d\n", d[pick].Name, wager * (d[pick].amounttopayout));
}
// otherwise
else
{
// Display the result greg lost the race with the dog names
printf("%s loose the race. %s wins the race.\n", d[pick].Name, d[raceresult].Name);
// Store the result for future use
sprintf(buffer, "%s loose the race. %s wins the race.\n", d[pick].Name, d[raceresult].Name);
}
}
// Create a function to store the previous races information
void previousraces(char **futureuse, int counter)
{
futureuse = futureuse;
counter = counter + 1;
}
// Create a main function of the program
int main(void)
{
// Create the structure dog d as like an object
struct DOG d[9];
int randomnum[100];
// Call the array of struct
arrayofstruct(d);
// call the random numbers function
randomnumbers(d, randomnum);
// Declare the required variable
// Which is not use globally
char selection;
char G, R, L;
char futureuse[1024][64];
int counter = 0;
// Create a do while to select the Greg selction
do
{
// select the menu
selection = menu();
// Note: Here, I'm providing the solution by using
// switch case or by using simple if-else
// Please use the approach which you want
// if you want to use switch case then go for continue
// or if you want to use if else then comment the switch
// case than comment from /*switch (selection) to ...
// last break } */ and remove comment from if else approach
switch (selection)
{
// If Greg selects [G] the program will
//ask Greg for his wager and allow Greg
// to pick a dog from a list
// When User select G
case 'G':
// Call the doginformation
doginformation(d, randomnum, futureuse[counter]);
// break command use inside the case not outside
break;
// If Greg selects [R] the program
//will show Greg the results of all
//previous races entered during
// this run of the program.
// When user select R
case 'R':
// Loop to access the future use result
for (int i = 0; i < counter; i++)
{
// display future use result
printf("%s", futureuse[i]);
}
break;
// If Greg selects [L] the program will end
// When user selct L
case 'L':
// Display Thank you message and program will end
printf("Thank you!!!. The program will end.\n");
break;
// Default case when Greg select wrong choice
default:
printf("Wrong selection!!\n");
break;
}
/*
if (selection == 'G')
{
doginformation(d, randomnum,futureuse[counter]);
}
else if(selection == 'R')
{
for(int i=0; i<counter; i++)
{
printf("%s",futureuse[i]);
}
}
else if (selection == 'L')
{
printf("Thank You!!!.\n");
}
else
{
printf("Wrong selection!!\n");
}*/
counter++;
}
while (selection != 'L');
}