Question: This is for C++ #include #include #include using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots
This is for C++
#include
#include
#include
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 the 1-way if statements with multi-way if statements with compound
conditions. Your
solution should have only 1 return statement.
*/
int main()
{
//int seed = 0;
int seed = (int)time(nullptr);
default_random_engine e(seed);
uniform_int_distribution
int die1 = u(e);
int die2 = u(e);
int sum = die1 + die2;
cout << "You rolled " << sum << " = " << die1 << " + " << die2 << endl;
if (sum == 2)
{
cout << "you lose" << endl;
return 0;
}
if (sum == 3)
{
cout << "you lose" << endl;
return 0;
}
if (sum == 12)
{
cout << "you lose" << endl;
return 0;
}
if (sum == 7)
{
cout << "you win" << endl;
return 0;
}
if (sum == 11)
{
cout << "you win" << endl;
return 0;
}
cout << "roll again" << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
