in c++ The following description has been adopted from Deitel & Deitel. One of t
ID: 3821497 • Letter: I
Question
in c++
The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps, " which is played in casinos and back alleys throughout the world. The rules of the game are straight forward: 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 "crops"), 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 Che 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. Write a program that implements a craps game according to the above rules. The game should allow for wagering. This means that you need to prompt that user for an initial bunk 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. As the game progresses, 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 chancel", or "You're up big, now's the time to cash in your chips!" Use the below functions to help you get started! You may define more than the ones suggested if you wish! void print_game_rules (void) - Prints out the rules of the game of "craps". double get_bank_balance (void) Prompts the player for an initial bank balance from which wagering will be added or subtracted. The player entered bank balance (in dollars, i.e. $100.00) is returned. double get_wager_amount (void) - Prompts the player for a wager on a particular roll. The wager is returned. Int check_wager_amount(double wager, double balance) - Checks to see if the wager is within the limits of the player's available balance. If the wager exceeds the player's allowable balance, then 0 is returned; otherwise 1 is returned. int roll_die (void) - Rolls one die. This function should randomly generate a value between 1 and 6, inclusively. Returns the value of the die. int calculate_sum_dice (int die1_value, int die2_value) Sums together the values of the two dice and returns the result. int is_win_loss_or_point (int sum_dice) - Determines the result of the first dice roll. If the sum is 7 or 11 on the roll, the player wins and 1 is returned. If the sum is 2, 3, or 12 on the first throw (called "craps"), the player loses (i.e. the "house" wins) and 0 is returned. If Che sum Is 4, 5, 6, 8, 9, or 10 on the first throw, then the sum becomes the player's "point" and -1 is returned. int is point loss of neither (int sum dice, int point_value) Determines the result of any successive roll after the first roll. If the sum of the roll is the point_value, then 1 is returned. If the sum of the roll is a 7, then 0 is returned. Otherwise, -1 is returned. double adjust_bank_balance (double bank_balance. double wager_amount, Int add_or_subtract) If add_or_subtract is 1, then the wager amount Is added to the bank_balance. If add_or_subtract is 0, then the wager amount is subtracted from the bank_balance. Otherwise, the bank_balance remains the same. The bank_balance result is returned. void chatter_messages (int number_rolls, int win_loss_neither, double initial_bank_balance. double current_bank_balance) - Prints an appropriate message dependent on the number of rolls taken so far by the player, the current balance, and whether or not live player just won his roll. The parameter win_loss_neither indicates the result of the previous roll. Others? A main () function that makes use of the above functions in order to play the game of craps as explained above. Note that you will most likely have a loop in your main () function (or you could have another function that loops through the game play).Explanation / Answer
//Program to implement Rolling Dice game according to rules.
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
//Methood to implent rolling dice
int roll()
{
return(rand() % 6 + 1);
}
int main()
{
int stake = 100, bet = 0;
int choice = 0;
int roll1, roll2, sum;
srand(time(NULL)); //seed
cout << "Welcome to the Dice Game!" << endl;
roll1 = roll();
roll2 = roll();
sum = roll1 + roll2;
cout << "opening roll: " << roll1 << " + " << roll2 << " = " << sum << endl;
while (stake > 0)
{
cout << "stake = " << stake << endl;
cout << "(0) quit or (1) bet? ";
cin >> choice;
if (choice == 1) {
cout << "how much? ";
cin >> bet;
while ((bet % 5 != 0) || (bet < 0) || (bet > 50)) {
cout << "illegal bet--please bet again:" << endl;
cout << "how much? ";
cin >> bet;
}
roll1 = roll();
roll2 = roll();
sum = roll1 + roll2;
cout << "roll: " << roll1 << " + " << roll2 << " = " << sum << endl;
if ((sum == 2) || (sum == 3) || (sum == 12)) {
cout << "you lose! try again!" << endl;
stake -= bet;
} else if ((sum == 7) || (sum == 11)) {
cout << "you win! try again!" << endl;
stake += bet;
} else
cout << "tie! try again!" << endl;
} else
return(0);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.