Question

In: Computer Science

"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...

"Gambling Greg" Assignment

Outcomes:

  • Demonstrate the ability to create and use structs
  • Demonstrate the ability to create and use menus
  • Demonstrate the ability to create and use an array of structs
  • Demonstrate the ability to generate and use random numbers

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%

Submission Requirements:

You must follow the rules from the first assignment. Don't forget your design tool!

DO NOT:

  • Use global variables
  • Use the goto command
  • Use the break command outside a case statement

Solutions

Expert Solution

Note: The provided solution is correct as per the question requirements. If you need further assistance feel free to comment in the comment section. I'm happy to help you. :)

Program code screenshot:

Sample output:

Program code to copy:

// 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');

}

Note: please give me positive response thank you:)


Related Solutions

"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to create and use menus Demonstrate the ability to create and use an array of structs Demonstrate the ability to generate and use random numbers 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...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate strings. Demonstrate the ability to write well written code. Program Specifications: DESIGN and IMPLEMENT a short program that will: Allow the user to enter a string with up to 100 letters. Display the user-entered string: Forward Backward Vertical As a triangle made from the letters of the string Display the number of letters in the string. Once everything above is displayed, the program will...
#C language array must store at least 50 inputs Game Scores Assignment Outcomes: Demonstrate the ability...
#C language array must store at least 50 inputs Game Scores Assignment Outcomes: Demonstrate the ability to create a menu driven program. Demonstrate the ability to create and use a 2D array on the stack. Demonstrate the use of functions. Demonstrate good programming style. Program Specifications: Your program will read in "game scores" from the user. Each score consists of a score for YOUR team and a score for the OTHER team. You don't need names or dates for the...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability to identify emerging ethical issues in business, interpret the multitude of perspectives inherent in your case study, and model appropriate behaviour by recommending specific solutions. How to Proceed Select a case. It can be one of the textbook cases that we have not discussed during the course. It can also come from the outside world, perhaps a case you have been following in the...
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret...
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret detailed policy. We have chosen for you to take a look at two of the most well known policies; in real life, you will have government polices such as these as well as enterprise specific policies or regulations. As you build information systems, it is key to early on in the process to identify all relevant policy drivers and understand them. In the module,...
In this assignment, you need to demonstrate your ability in using input, output, data types, and...
In this assignment, you need to demonstrate your ability in using input, output, data types, and if statement in C++ program. Assume that you need write a C++ program for a cash register. There are only four items in the store: Cereal, $3.99 Milk, $3.99 Egg, $0.25 Water, $ 1.50 Once a customer purchases items, you will ask her/his how many of them are bought. The quantity can be in the range of 0-10 (including 0 and 10). Then, calculate...
C Programming Game Scores Assignment Outcome: Student will demonstrate the ability to design a menu driven...
C Programming Game Scores Assignment Outcome: Student will demonstrate the ability to design a menu driven program. Student will demonstrate the ability to create and use a 2D array on the stack. Student will demonstrate the use of functions. Student will demonstrate good programming style. Program Specifications: *********************************************** ** MAIN MENU ** *********************************************** A) Enter game results B) Current Record (# of wins and # of losses and # of ties) C) Display ALL results from all games WON D)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT