C++ language (need help filling the rest) Use the following description of the g
ID: 3587238 • Letter: C
Question
C++ language (need help filling the rest)
Use the following description of the game of dice to solve the attached puzzle.
What are dice or what is a die – the singular form of dice?
A die is a cube of some hard, durable material, usually white in color. On each face of a die are a number of spots, usually black in color, arranged symmetrically on the face, each face having a different number of spots, ranging in number from one to six.
One player plays until he wins or loses. The player tosses a pair of dice on the ground and counts the number of spots on the upper most faces of the dice.
A player either wins or loses, as craps allows no tie games. The game ends as soon as a player wins or loses. A player wins, loses or defines his point on the first toss of the dice. A player who defines his point continues to toss the dice until he wins or loses.
A player who tosses 7 or 11 on the first toss wins. A player who tosses 2, 3 or 12 loses on the first toss. A player who tosses anything else defines his point and tosses until he tosses his point again and wins or tosses 7 and loses.
//random number includes
#include <ctime>
#include <random>
//standard includes
#include <string>
#include <iostream>
using namespace std;
int main()
{
default_random_engine e;
uniform_int_distribution<int> u(1, 6);
// puzzle begins
int roll_count = 1;
int point = die_sum;
roll_count++;
int die1 = u(e);
int die2 = u(e);
die1 = u(e);
die2 = u(e);
int die_sum = die1 + die2;
die_sum = die1 + die2;
cout << "You rolled " << die_sum << " (" << die1 << " and " << die2 << ")"
<< " on roll " << roll_count << endl;
cout << "You rolled " << die_sum << " (" << die1 << " and " << die2 << ")"
<< " on roll " << roll_count << endl;
cout << "You win on the first roll";
cout << "You lose on the first roll";
cout << "You win on roll " << roll_count << endl;
cout << "You lose on roll " << roll_count << endl;
cout << "Your point is " << point << endl;
cout << "Roll again!" << endl;
do
else
else
else
if(die_sum == 2 || die_sum == 3 || die_sum == 12)
if (die_sum == 7 || die_sum == 11)
if (die_sum == 7)
while (die_sum != 7 && die_sum != point);
{}
{}
// puzzle ends
cout << endl;
system("pause");
return 0;
}
Explanation / Answer
#include <cstdlib>
//random number includes
#include <ctime>
#include <random>
//standard includes
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
default_random_engine e;
uniform_int_distribution<int> u(1, 6);
// puzzle begins
int roll_count = 1;
int die_sum = 0;
int point = 0;
int die1=u(e);
int die2 =u(e);
die1 = u(e);
die2 = u(e);
die_sum = die1 + die2;
// display the message of rolled dice
cout << "You rolled " << die_sum << " (" << die1 << " and " << die2 << ")"
<< " on roll " << roll_count << endl;
//checks for the first roll win or lose
if (die_sum == 7 || die_sum == 11) {
cout << "You win on the first roll";
} else if (die_sum == 2 || die_sum == 3 || die_sum == 12) {
cout << "You lose on the first roll";
} else {
// again toss the dice until lose or win
while ((die_sum != 7)&&(die_sum != 2 || die_sum != 3 || die_sum != 12)) {
point = point + die_sum;
die1 = u(e);
die2 = u(e);
die_sum = die1 + die2;
roll_count++;
cout << "You rolled " << die_sum << " (" << die1 << " and " << die2 << ")"
<< " on roll " << roll_count << endl;
}
//checks for dice win or lose
if (die_sum == 7) {
cout << "You win on roll " << roll_count << endl;
} else {
cout << "You lose on roll " << roll_count << endl;
}
}
cout << "Your point is " << point << endl;
cout << "Roll again!" << endl;
// puzzle ends
cout << endl;
system("pause");
return 0;
}
sample output:
You rolled 8 (5 and 3) on roll 1
You rolled 6 (4 and 2) on roll 2
You rolled 6 (1 and 5) on roll 3
You rolled 11 (5 and 6) on roll 4
You rolled 7 (3 and 4) on roll 5
You win on roll 5
Your point is 31
Roll again!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.