Question

One of the most popular games of chance is a dice game known as “craps”, played...

One of the most popular games of chance is a dice game known as “craps”, played in casinos around the world. Here are the rules of the game:

A player rolls two six-sided die, which means he can roll a 1, 2, 3, 4, 5 or 6 on either die. After the dice come to rest they are added together and their sum determines the outcome. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3, or 12 on the first roll, the player loses (this is called “craps”). If the player rolls 4, 5, 6, 8, 9, or 10 on the first throw, then that becomes the player’s “point”. To win, the player must “make their point”, that means that they must roll the sum they got on that first throw, so they keep rolling the dice. The player loses by rolling a 7 before making the point.

Part 1: The basic program
a)   Write a flow chart or pseudo code for part 1 of the homework.

b)   Write a C++ program that simulates the playing of this game with two players. You will need:
1.   An introduction to your program with instructions and your name.
2.   The players are prompted for a random number seed.
3.   A function that generates the random numbers and prints the results to the interface. Two separate random numbers must be generated for the two die, not the sum. This function returns the toss of one die after the user is prompted to tap the spacebar.
4.   The program alternates players rolling the die.
5.   The program keeps track of the number of wins for each player.
6.   The program tells the users if player 1 or 2 wins after 3 points are won.
7.   Write the output to a file.

Part 2: Wagering
The program must ask the users if they want to gamble. This option will bypass a finite limit number of plays. Both players start with a bank balance of $1000 dollars. Each turn, players are asked to enter a minimum wager of $100. If the player wins, the balance is increased by the wager, if they lose, it is decreased. The program continues as long as the player has a positive bank balance, and they cannot wager more than is in the bank. When they lose, give a message like “Player X, you’re busted!”, and you can send other messages….

Homework Answers

Answer #1

Hi,

writing the program itself took a lot of time.. Sorry I could not prepare the flowchart..

Please find the code below for Part 1.

For part 2, its very simple modification to do in this program... please try.. if you are unable to do, let me know will help you in that.

#include <iostream>
#include <cstdlib>
#include <ctime>

// namespace included.
using namespace std;

unsigned int rollDice();

int main(){

    // variables declared.
    unsigned int myPoint = 0;
    unsigned int sumOfDice;

    // pointsA and pointsB take care of points won by PlayerA and PlayerB.
    int pointsA = 0;
    int pointsB = 0;

    // flag takes care of who is playing the game.
    // flag = true -> Player A is playing
    // flag = false -> Player B is playing.
    bool flag = true;

    // die1 and die2 have the die value returned from rollDice() function.
    int die1 = 0;
    int die2 = 0;

    // repeat the loop till either Player wins.
    while ((pointsA != 3) && (pointsB != 3)){
        // Player A is playing
        if(flag){
            cout << endl << "-----------------------------------------" << endl;
            cout << "Player 1 is playing" << endl;
            cout << "Current points are " << pointsA << endl;
            cout << "For Die 1," << endl;
            die1 = rollDice();
            cout << "Player 1 has got " << die1 << " in die1" << endl;
            cout << "For Die 2," << endl;
            die2 = rollDice();
            cout << "Player 1 has got " << die2 << " in die2" << endl;
            sumOfDice = die1 + die2;
            cout << "Sum of the Dice is " << sumOfDice << endl;
        }
        // PlayerB playing
        else{
            cout << endl << "-----------------------------------------" << endl;
            cout << "Player 2 is playing" << endl;
            cout << "Current points are " << pointsB << endl;
            cout << "For Die 1," << endl;
            die1 = rollDice();
            cout << "Player 2 has got " << die1 << " in die1" << endl;
            cout << "For Die 2," << endl;
            die2 = rollDice();
            cout << "Player 2 has got " << die2 << " in die2" << endl;
            sumOfDice = die1 + die2;
            cout << "Sum of the Dice is " << sumOfDice << endl;
        }

        switch(sumOfDice){

            // if the sumOfDice is 7 or 11, points gained.
            case 7:
            case 11:
                    if(flag)
                        pointsA++;
                    else
                        pointsB++;
                    break;

            // if sumOfDice is 2,3, or 12, points lost.
            case 2:
            case 3:
            case 12:
                    if(flag)
                        pointsA--;
                    else
                        pointsB--;
                    break;

            // if we are in this case, try to "make point" as in the program description.
            default:
                    myPoint = sumOfDice;
                    cout << "Point is " << myPoint << endl;
                    cout << "Roll again" << endl;
                    cout << "For Die 1," << endl;
                    die1 = rollDice();
                    cout << "For Die 2," << endl;
                    die2 = rollDice();
                    sumOfDice = die1 + die2;

                    if(sumOfDice == myPoint){
                        if(flag)
                            pointsA++;
                        else
                            pointsB++;
                    }
                    else{
                        if(flag)
                            pointsA--;
                        else
                            pointsB--;
                    }
                    break;
        }
        // Change the player
        flag = !flag;
    }

    cout << endl << endl << endl;
    // check who has won the game.
    if(pointsA == 3)
        cout << "PlayerA wins" << endl;
    else if (pointsB == 3)
        cout << "PlayerB wins" << endl;

}

// return the dice value.
unsigned int rollDice(){
    int n = 0;
    cout << "Enter the seed number: " << endl;
    cin >> n;

    // srand takes the different seed each time based on the user input.
    srand(n);

    unsigned int die = 1 + rand() %6;

    return die;
}

OUTPUT:
$ g++ craps.cpp
$ ./a.out

-----------------------------------------
Player 1 is playing
Current points are 0
For Die 1,
Enter the seed number:
12
Player 1 has got 3 in die1
For Die 2,
Enter the seed number:
123
Player 1 has got 2 in die2
Sum of the Dice is 5
Point is 5
Roll again
For Die 1,
Enter the seed number:
234
For Die 2,
Enter the seed number:
345

-----------------------------------------
Player 2 is playing
Current points are 0
For Die 1,
Enter the seed number:
56
Player 2 has got 4 in die1
For Die 2,
Enter the seed number:
45
Player 2 has got 5 in die2
Sum of the Dice is 9
Point is 9
Roll again
For Die 1,
Enter the seed number:
34
For Die 2,
Enter the seed number:
456

-----------------------------------------
Player 1 is playing
Current points are -1
For Die 1,
Enter the seed number:
345
Player 1 has got 4 in die1
For Die 2,
Enter the seed number:
4567
Player 1 has got 4 in die2
Sum of the Dice is 8
Point is 8
Roll again
For Die 1,
Enter the seed number:
3
For Die 2,
Enter the seed number:
4566

-----------------------------------------
Player 2 is playing
Current points are -1
For Die 1,
Enter the seed number:
4567
Player 2 has got 4 in die1
For Die 2,
Enter the seed number:
352
Player 2 has got 2 in die2
Sum of the Dice is 6
Point is 6
Roll again
For Die 1,
Enter the seed number:
23
For Die 2,
Enter the seed number:
23

-----------------------------------------
Player 1 is playing
Current points are -2
For Die 1,
Enter the seed number:
234
Player 1 has got 6 in die1
For Die 2,
Enter the seed number:
23
Player 1 has got 3 in die2
Sum of the Dice is 9
Point is 9
Roll again
For Die 1,
Enter the seed number:
423
For Die 2,
Enter the seed number:
23
..
.
.

.
.
.
.
.
..

..

..

.After a lot of trials, finally I got the output as below

-----------------------------------------
Player 1 is playing
Current points are 2
For Die 1,
Enter the seed number:
Player 1 has got 2 in die1
For Die 2,
Enter the seed number:
Player 1 has got 2 in die2
Sum of the Dice is 4
Point is 4
Roll again
For Die 1,
Enter the seed number:
For Die 2,
Enter the seed number:


PlayerA wins
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps is a game played with a pair of dice. In the game, the shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the “coming out” roll) is a 7 (“natural”) or 11 (“yo-leven”), the shooter immediately wins the game. If the coming out...
Use CPP This question is about providing game logic for the game of craps we developed...
Use CPP This question is about providing game logic for the game of craps we developed its shell in class. THe cpp of the class is attached to this project. At the end of the game, you should ask user if wants to play another game, if so, make it happen. Otherwise quit. craps.cpp /*** This is an implementation of the famous 'Game of Chance' called 'craps'. It is a dice game. A player rolls 2 dice. Each die has...
Craps is a dice game in which the players make wagers on the outcome of the...
Craps is a dice game in which the players make wagers on the outcome of the roll, or a series of rolls, of a pair of dice. Most outcomes depend on the sum of the up faces of two, fair, six-sided dice. A) Describe the sample space for all possible outcomes of rolling two dice. How many ways are there to roll a 5? b)Determine all possible random variable values and the probability of those outcomes. Find the probability of...
Bunco is a group dice game that requires no skill. The objective of the game is...
Bunco is a group dice game that requires no skill. The objective of the game is to accumulate points by rolling certain combinations. The game is played with three dice, but we will consider a simpler version involving only two dice. How do you play two dice Bunco? There are six rounds, one for each of the possible outcomes in a die, namely the numbers one through six. Going clockwise, players take turns rolling two dice trying to score points....
Problem 4)A simplified version of the dice game 10,000 is played using 5 dice. The player...
Problem 4)A simplified version of the dice game 10,000 is played using 5 dice. The player rolls the 5 six-sided dice, each 1 that is rolled, the player achieves a score of 100. A) How many possible ways are there to roll i l's over these 5 dice? (Hint: use combinations) B) The probability of any one dice rolling to a value of 1 is 1/5 (since each dice has six sides). Use the binomial probability distribution. Calculate the probability...
Players A and B take turns at rolling two dice, starting with A. The first person...
Players A and B take turns at rolling two dice, starting with A. The first person to get a sum of at least 9 on a roll of the two dice wins the game. Find the probability that A will win the game if: (a) the game is just about to begin (b) 8, 4, 3, 7 and 7 have already been rolled (c) a draw is to be declared in the event of no-one winning within 6 rolls.
Players A and B take turns at rolling two dice, starting with A. The first person...
Players A and B take turns at rolling two dice, starting with A. The first person to get a sum of at least 9 on a roll of the two dice wins the game. Find the probability that A will win the game if: (a) the game is just about to begin (b) 8, 4, 3, 7 and 7 have already been rolled (c) a draw is to be declared in the event of no-one winning within 6 rolls.
The game requires $5 to play, once the player is admitted, he or she has the...
The game requires $5 to play, once the player is admitted, he or she has the opportunity to take a chance with luck and pick from the bag. If the player receives a M&M, the player loses. If the player wins a Reese’s Pieces candy, the player wins. If the player wins they may roll a dice for a second turn, if the die rolls on a even number, they may pick from the bag once again with no extra...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
You are playing another dice game where you roll just one die--this time, you lose a...
You are playing another dice game where you roll just one die--this time, you lose a point if you roll a 1. You are going to roll the die 60 times. Use that information to answer the remaining questions. A. What are the values of p and q? (Hint: notice this is binomial data, where p is the probability of losing a point and q is the probability of not losing a point.) p =    and q = B....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT