Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE C PROGRAMMING LANGUAGE ( Need help from question 5 to 8) 1. get_bet This function should take the amount of money the user has

USE C PROGRAMMING LANGUAGE ( Need help from question 5 to 8)

1. get_bet This function should take the amount of money the user has to play with as an argument. It should prompt the user for the amount of money they want to bet, repeatedly until a valid bet is entered. The following values are considered invalid entries: -less than MIN_BET -higher than bankroll The function will return the amount of the valid bet entered by the user. The function can assume that the user will only enter values that are integers (ie. it will not have to handle characters or floating point number entries)

2. play_again This function takes no arguments. It should prompt the user to determine whether they want to play again repeatedly until a valid choice is entered. A valid choice is: 1 if they want to play again or 0 if they don't want to play again. The function will return 1 if they want to play again, 0 if they dont. The function can assume that the user will only enter values that are integers (ie. it will not have to handle characters or floating point number entries)

3. compute_winnings This function takes a number representing the number of dice rolled that match the users guess and the amount the user bet. It should calculate the amount the user has won (a positive number), or lost (a negative number) based on the following odds:

-1 dice matching, player gets 1:1 odds on their bet, 2 dice matching, player gets 2:1 odds on their bet, 3 dice matching, player gets 10:1 odds on their bet -0 dice matching, player loses their whole bet

The function will return the amount of money won (a positive number), or lost (a negative number)

4. get_guess This function takes no arguments. It should prompt the user for a valid dice roll guess. An invalid guess is number smaller than 1 or bigger than 6. The function will return the valid guess. The function can assume that the user will only enter values that are integers (ie. it will not have to handle characters or floating point number entries)

5. roll_dice. This function takes 3 pointers to integers that represent the locations of the values of the 3 rolled dice. The function will generate 3 random numbers (from 1 to 6 inclusive) and store these numbers at the addresses given by the function arguments. The function should use the built-in rand function included in stdlib.h that has the following documentation: https://www.tutorialspoint.com/c_standard_library/c_function_rand.htm NOTE: we have called srand for you in the main function provided you DO NOT need to call it again in this function, it is sufficient to just call the rand function to get your next random value. See the comments in main to help with testing versus running a realistic version of the game.

6. count_matches. This function takes the value of the users guess and 3 dice roll values. It should count the number of the dice roll values that match the users guess. The function will return the number of dice roll values that match the users guess.

7. play_round. This function takes the amount of a users bet as an argument (it can assume the bet is valid). The function will then play one round of the game by getting the users guess, rolling the dice and calculating the amount they won lost. The function will return the amount of money won (a positive number), or lost (a negative number).

8. play_game. This function takes a pointer to an integer representing the amount of money the user has available to bet with (their bankroll). The function should continually allow the user to play rounds of the game while they still have enough money in their bankroll to make a minimum bet and they still want to play. The function should update the bankroll at the end of each played round based on the amount won/lost in that round. After the user is done playing rounds, the function should print how much is left in their bankroll.

TEMPLATE

#include #include #include

#define MIN_ROLL 1 #define MAX_ROLL 6 #define MIN_BET 5

int get_bet(int bankroll); int play_again(); int compute_winnings(int num_matches, int bet); int get_guess(); void roll_dice(int* die1, int* die2, int* die3); int count_matches(int guess, int die1, int die2, int die3); int play_round(int bet); void play_game(int* bankroll);

int main(void) { // we have called srand with a constant value 0 for testing purposes // with this call, you will always get the same sequence of numbers generated // this allows you to anticipate what the dice rolls will be and let you test play_game more easily srand(0);

// instead of using call srand(0) as shown above: // use this call srand(time(0)) to mimic a new set of random numbers every time you play the game // this is a much more real game that you can get your friends to play // srand(time(0)); // a test for get_bet /* int bet = 0;

printf("testing get_bet with $300 bankroll "); bet = get_bet(300); printf("finished testing get_bet, returned result: %d", bet); printf("(returned result will be dependant on user input, cannot be >300) "); */

// some tests for compute_winnings /* int winnings_result = 0;

printf("testing compute_winnings with 0 matches and $50 "); winnings_result = compute_winnings(0, 50); printf("finished testing compute_winnings, returned result: %d (should be -50) ", winnings_result);

printf("testing compute_winnings with 1 match and $150 "); winnings_result = compute_winnings(1, 150); printf("finished testing compute_winnings, returned result: %d (should be 150) ", winnings_result);

printf("testing compute_winnings with 2 matches and $30 "); winnings_result = compute_winnings(2, 30); printf("finished testing compute_winnings, returned result: %d (should be 60) ", winnings_result);

printf("testing compute_winnings with 3 matches and $25 "); winnings_result = compute_winnings(3, 25); printf("finished testing compute_winnings, returned result: %d (should be 250) ", winnings_result); */

// some tests for count_matches /* int match_count = 0;

printf("testing count_matches with none matching "); match_count = count_matches(4, 3, 5, 1); printf("finished testing count_matches, returned value: %d (should be 0) ", match_count);

printf("testing count_matches with 1 matching "); match_count = count_matches(2, 2, 5, 3); printf("finished testing count_matches, returned value: %d (should be 1) ", match_count);

printf("testing count_matches with 2 matching "); match_count = count_matches(3, 3, 5, 3); printf("finished testing count_matches, returned value: %d (should be 2) ", match_count);

printf("testing count_matches with 3 matching "); match_count = count_matches(5, 5, 5, 5); printf("finished testing count_matches, returned value: %d (should be 3) ", match_count);

*/ // a test for play_round /* printf("testing play_round with $30 bet "); int round_result = play_round(30); printf("finished testing play_round with $30 bet, returned value was: %d ", round_result); */ return 0; }

// Write your function defintions here:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions