Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For C++: Create a Visual Studio Project Add your solution to class 4 problem 3 t

ID: 3755223 • Letter: F

Question

For C++:

Create a Visual Studio Project Add your solution to class 4 problem 3 to the project Change the name of the file to class 4 problem 4 Add an outer for loop to your solution to classwork 4 problem 3 that plays craps in the inner loop 1000 times. Remove all of the output statements from the inner loop craps game. When the outer loop ends display how times the player won and how many times the player lost. The player should win about 497 times and lose 503 times. Upload the modified cpp file.

This is class 4 problem 3:

#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,

and athing else is call the point and the player rolls again

1. replace the 1 way if statements with 1-multi-way if statement

2. add a while loop to the final else that rolls the dice until the game

ends

*/

int main()

{

//int seed = 0;

int seed = (int)time(nullptr);

default_random_engine e(seed);

uniform_int_distribution<int> u(1, 6);

int die1 = u(e);

int die2 = u(e);

int sum = die1 + die2;

cout << "You rolled " << sum << " = " << die1 << " + " << die2 <<

endl;

if (sum == 2 || sum == 3 || sum == 4)

{

cout << "you lose" << endl;

return 0;

}

if (sum == 7 || sum == 11)

{

cout << "you win" << endl;

return 0;

}

cout << "roll again until you roll 7 and lose or roll your point ("

<< sum << ") and win!" << endl;

return 0;

}

Explanation / Answer

//C++ program

#include <random>

#include <iostream>

#include <ctime>

using namespace std;

int main()

{

int seed = (int)time(NULL);

default_random_engine e(seed);

uniform_int_distribution<int> u(1, 6);

int die1,die2,sum,i=0,point;

int win=0,loss=0;

while(i<1000){

die1 = u(e);

die2 = u(e);

sum=die1 + die2;

cout<<"you rolled "<<sum<<" = "<<die1<<" + "<<die2<<" ";

if(i==0){

if(sum==2||sum==3||sum==4)

loss++;

else if(sum==7||sum==11)

win++;

point=sum;

}

else{

if(sum==point)

win++;

else loss++;

}

i++;

}

cout<<"Win : "<<win<<" Loss : "<<loss<<" ";

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote