Question

This is in C++. The program needs to show the points as well. The blue boxes show below are the output and it should look like that. Thanks

(Game: craps) Craps is a popular dice game played in casinos. Write a program to play a variation of the game, as follows: Ro

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
 *  C++ Program
 */

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
  srand(time(NULL));

  int dice1, dice2 = 0;
  int rollDice, sum2;

  dice1 = rand() % 6 + 1;
  dice2 = rand() % 6 + 1;
  rollDice = dice1 + dice2;

  cout << "Your rolled " << dice1 << " + " << dice2 << " = " << rollDice << endl;

  if (rollDice == 7 || rollDice == 11)
  {
    cout << "You win" << endl;
  }
  else if (rollDice == 2 || rollDice == 3 || rollDice == 12)
  {
    cout  << "You lose" << endl;
  }
  else if (rollDice == 4 || rollDice == 5 ||rollDice == 6 ||rollDice == 8 || rollDice == 9 || rollDice == 10)
  {
    cout << "point is " << rollDice << endl;

    dice1 = rand() % 6 + 1;
    dice2 = rand() % 6 + 1; 
    sum2 = dice1 + dice2;
    
    cout << "Your rolled " << dice1 << " + " << dice2 << " = " << sum2 << endl;

    if (sum2 == rollDice)
    {
      cout << "You win" << endl;
    } 
    else if( sum2 == 7 )
    {
      cout  << "You lose" << endl;
    }
  }
  
  return 0;
}

Files D e main.cpp 2 saved https://Comfortable AquamarineResource.imtusharsharma.repl.run K main.cpp 1 2 3 /* * * C++ Program

Add a comment
Know the answer?
Add Answer to:
This is in C++. The program needs to show the points as well. The blue boxes...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation...

    in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation program to estimate the winning chance of the Craps game. Craps is a popular dice game played in casinos. Here is how to play: Roll two dice. Each die has 6 faces representing values 1,2,3,4,5,and 6, respectively. Check the sum of 2 dice. If the sum is 2, 3, or 12 (called craps), you lose; if the sum is 7 or 11 (called natural),...

  • Craps

    Write a C++ game that plays Craps. Craps is a game played with a pair of dice. 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 ‘come out roll’) is a 7 or 11, the shooter wins the game. If the opening roll results in a 2 (snake eyes), 3 or 12 (box cars), the shooter loses,...

  • Java Craps in Java. The following are the rules for a pass bet in the game...

    Java Craps in Java. The following are the rules for a pass bet in the game of craps. Roll two six-sided dice, and let x be their sum. If x is 7 or 11, you win. If x is 2, 3, or 12, you lose. Otherwise, repeatedly roll two the dice until their sum is either x or 7. If their sum is x, you win. If their sum is 7, you lose. Compose a modular program to estimate the...

  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • Problem 9 A single game of craps (a dice game) consists of at most two rolls...

    Problem 9 A single game of craps (a dice game) consists of at most two rolls of a pair of six sided dice. The ways to win are as follows: Win-the first roll of the pair of dice sums to either 7 or 1 (you win, game over, no second roll Win the first roll of the pair of dice does NOT sum to either 7 or 1 but the sum of the second roll is equal to the sum...

  • This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the...

    This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...

  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...

  • Java programming Write a simulation of the Craps dice game. Craps is a dice game that...

    Java programming Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes. Craps game rules: First roll: The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses...

  • in c programming and c++filed Exercise 1: A Game of guessing number Set the default upper...

    in c programming and c++filed Exercise 1: A Game of guessing number Set the default upper and lower limits to be 1-100, and ask you to guess a number. If you do not guess the correct number, the program will nicely" automatically adjust the upper or the lower limits to save your day until you guess it. 2 0 12. 51 - 100 3 2 51 74 22 65 74 85 2 71 74 3 . 2 73 74 75...

  • III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of...

    III. Overview & Requirements: 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 straightforward: 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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT