Question

The basic rules of Craps are as follows:

If the player bets "for" him/herself:
·         if the first roll of the dice results in a 7 or 11, then the player immediately wins the amount of the bet;
·         if the first roll of the dice results in a 2, 3 or 12, then the player immediately loses the amount of the bet;
·         if the first roll is a number other than 2, 3, 7, 11 or 12, the number that is rolled is called the player's "point."
o   The player may increase ("press") the amount of his/her bet at this point. For purposes of this game, the player should be allowed to double the amount of the bet.
o   At this point, the player's goal is to roll the same "point" again *before* rolling a 7 (called "sevening out").

If the player bets "against" him/herself, the result is basically a mirror image of the above. Here are the rules:
·         if the first roll of the dice results in a 2, 3 or 12, then the player immediately wins the amount of the bet;
·         if the first roll of the dice results in a 7 or 11, then the player immediately *loses* the amount of the bet;
·         if the first roll is a number other than 2, 3, 7, 11 or 12, then the player who bets against him/herself is betting that s/he will roll a 7 *before* rolling the "point" second time.
o   If the 7 is rolled, the player wins; if the point is rolled first, the player loses.
o   As when betting for him/herself, the player should be allowed to double the amount of the bet if he/she wishes.

When the player has either "sevened out" or "made the point," the game is completed, and a new game begins. If the player won, s/he must decide whether to pick up his/her chips and quit or to play another game.

Your program should give the player an initial betting billfold of $100.00. The minimum bet is $5.00. For purposes of this game, there is no maximum bet other than the amount of money available.
You will need to design and implement several functions.

You will need to decide on appropriate variables in which to store the player's bank roll (in order to keep track of how much money the player has), how many times the player won and lost, and how many times the player bet for and against him/herself. This bank roll should be kept up to date on the player's current status, which means that wins should be added and losses should be subtracted from the bankroll as the user plays the game. After each game, the program must report the result of the game, the amount of money won or lost, the current value of the bank roll, how many times the player won and lost, and how many times the player bet for and against him/herself. After each game, the program should allow the player to continue playing until s/he chooses to quit, or until the player runs out of money. This central program control may be done within main().

"Rolling" the dice:

A separate rolling() function will be used to "roll" the dice. This function will contain two die variables. You will initialize each variable separately using a random number generator. The possible values are one through six, corresponding to the six sides of a regular die. This function will return the sum of the two variables. Also, the function will print the value of each die after it is rolled (but not the total). For help on using the rand random number generator to generate random numbers for use in your program, click here.

"Playing" the game:

A second function playing() will be used to play a single game of craps until the player either wins or loses a bet, based upon the rules given above. This function should be passed the current $ amount of the player's bank roll and should return the amount of money left, whether the player won or lost, and whether the player bet for or against him/herself. Within the function, the player is asked whether s/he would like to place a bet. If so, the player must choose whether to bet "for" or "against" him/herself (see game rules above). The player then "rolls the dice" (simulated by a call to the dice-rolling function rolling()). This should be done interactively (via a key press from the player), rather than simply having the program continuously roll the dice until the game is over. After each roll, this function should report the total value of the dice (after receiving this value from the dice-rolling function). If, after the first roll, the game is not over, the player should be asked whether s/he would like to double the amount of the bet. When a roll causes the end of a game, the player is notified whether s/he won or lost money in that game overall, and the amount won or lost. In all other cases, the player is notified that s/he needs to roll again.
"Ending" the game:

You need a separate function ending() to do the following: you should report the current value of the bank roll, how many times the player won and lost, and how many times the player bet for and against him/herself. You need to save the above information into a text file as well.

As optional, you need a separate function beginning() to do the following at the beginning of your program in main(): the function will open the text file you used to save game information for reading if it exists so that your game can continue from previous played results. The function will initialize the bank roll, the times the player won or lost, and the times the player bet for or against him/herself.

Additional functions may be necessary and/or appropriate, depending upon the final overall design of your program.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int playing(int total, int *wins, int *betWho);
int doubleBet(int bet, int total);
void ending(int total, int games, int wins, int betForSelf);
int rolling();

int main()
{
int total = 100; //Total starting money $100
int betWho = 0, wins = 0, games = 0; //Counters
char answer;
while(1) //Main body to run code
{
games++; //Increment game counter
total = playing(total, &wins, &betWho); //Run game

if(total > 0) //If we have more than 0 dollars left ask if you want to play again
{
do
{
printf("Would you like to play more(Y/N): ");
scanf("%c", &answer);
}while(answer != 'Y' && answer != 'N');
if(answer == 'N')
break;

}

}
ending(total, games, wins, betWho); //Print results and end game
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Lists in C++
Homework Solution
$25.00
Programming
Computer Science
C++
Nodes
Lists
Pointers
Algorithms
Header
Data
Inserting
Functions
Elements
Statements
Iterations
Matrix Multiplication
Homework Solution
$23.00
Matrix
Multiplication
Computer
Science
C-Family
Programming
Print
Results
Input
Output
Values
Label
Associative Arrays in C++
Homework Solution
$75.00
Programming
C++
Associative Arrays
Computer Science
Hash Tables
Chaining
Static Arrays
Game of Life
Records
Strings
Integers
Objects
Functions
Copying
Applet
Sequences
Lists
Prime Numbers
Simulations
Get help from a qualified tutor
Live Chats