Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help programming a game in the language C: You will modify a program of craps so that is simulates play in a casino, in

Need help programming a game in the language C:

You will modify a program of craps so that is simulates play in a casino, in a 'gambling' situation. As you may know, the game of craps is dice game, and is one of the most popular games of chance. The rules of the game are straightforward (and the provided craps.c contain some of these rules, if not all).A player rolls two dice. Each die has six faces.These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e., the"house" wins).If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point." To win, you must continue rolling the dice until you "make your point." The player loses by rolling a 7 before making the point. To retrieve starting place: mkdir P1; cd P1 ; cp ~ingrid/1730/P1/* ./

The game should allow for wagering. This means that you need to prompt that user for an initial bank balance from which wagers will be added or subtracted. Before each roll prompt the user for a wager. Once a game is lost or won, the bank balance should be adjusted.

All user input should be validated, e.g.,:

  1. Initial bank balance is a positive number
  2. Wagers must be less than or equal to the available balance.

As the game progresses, your program should print various messages to create some "chatter" such as, "Sorry, you busted!", or "Oh, you're going for broke, huh?", or "Aw cmon, take a chance!", or "You're up big, now's the time to cashin your chips!"

Here are some assumptions of your program.

  • The gambler can play multiple games of craps.
  • The gambler wagers money at each game of craps.

Minimal Requirements:

You should structure you program as a set of functions, e.g., one game of craps should be structures as at least function. Here are some required functions (some of the below have more complete descriptions, such as return types, and parameters, and some do not - you should think about the missing parameters on your own).

  • void printGameRules(void): Prints out the rules of craps.
  • double getBankBalance(void): Prompts the player for an initial bank balance from which wagering will be added orsubtracted. The player entered bank balance (in dollars, i.e., $100.00) is returned.
  • int checkWager(double wager, double balance): This function gets a wager amount as a parameter and checks to make sure it doesnt exceed the players current bank balance. If the wager is less than or equal to the current bank balance, the function returns 1 (true), otherwise it exceeds - and returns 0 (false).
  • double getWager(void): Prompts the player for a wager on a particular roll. The wager is returned.
  • playGame(): Plays a single game of craps, rolling the dice as many times as necessary and printing the result to standard output (the terminal). It returns to the caller one of the enumerated constants WON or LOST.
  • double adjustBalance(double bankbalance, double wageamount, int addOrSubtractToBalance ): This function either adds the wager to or subtracts the wager from the players current balance, depending upon whether the last game played was WON or LOST.
  • getYESorNO(): This function asks if the player would like to play another game of craps. The function checks the response to make sure it is either 'y' or 'n'. The function should repeatedly ask for a y/n response until a valid response is entered. getYesOrNo should return 1 (TRUE) if the answer is 'y' and 0 (FALSE) if the answer is 'n'. Assumption: only called if the player has a non zero balance.

In the comments of your code, for each function, you should write pre- and post-conditions of the function, describe the parameters, and return type. As you code you should design the function as a black box, define the prototype, then write a stub, and, once the program compiles successfully with each stub, fill in the function definitions (one at a time).

Suggested Include Files:

  • stdio.h: provides printf(), scanf(), getchar()
  • stdlib.h: provides rand(), srand()
  • time.h: provides time, which as you know, "seed" the random number generator.

Useful Functions.

  • system("cls"): clear screen.
  • system("pause"): press any key to continue.

Please include makefile.

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

Students also viewed these Databases questions

Question

Do you currently have a team agreement?

Answered: 1 week ago

Question

c. How is trust demonstrated?

Answered: 1 week ago

Question

c. Will leaders rotate periodically?

Answered: 1 week ago