Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming language is C++ 8-3 Source Code: #include #include #include using namespace std; //Declaring Global variables int roll_count = 0; //Function declarations void playOneGameOfCraps(); int

Programming language is C++

image text in transcribed

8-3 Source Code:

#include

#include

#include

using namespace std;

//Declaring Global variables

int roll_count = 0;

//Function declarations

void playOneGameOfCraps();

int rollOneDice();

void FirstRoll();

void OtherRolls(int point);

//Main method

int main()

{

//Calling the function

playOneGameOfCraps();

return 0;

}

//Function implementation which have the code to play the game

void playOneGameOfCraps()

{

int seedVal = 0;

//t is a 'time_t' type variable

time_t t;

seedVal = (unsigned)time(&t);

srand(seedVal);

FirstRoll();

}

void FirstRoll()

{

int sum = 0;

char ch;

int point;

sum = rollOneDice();

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

cout

ch = 'W';

}

else if (sum == 2 || sum == 3 || sum == 12) {

cout

}

else if (sum == 4 || sum == 5 || sum == 6 || sum == 8 || sum == 9 || sum == 10) {

point = sum;

cout

OtherRolls(point);

}

}

void OtherRolls(int point)

{

int sum = 0;

while (true) {

sum = rollOneDice();

cout

if (sum == point) {

cout

break;

}

else if (sum == 7) {

cout

break;

}

else

continue;

}

}

int rollOneDice()

{

int sum = 0;

for (int i = 0; i

sum += rand() % 5 + 1;

}

roll_count++;

return sum;

}

PA 9-4 (25 points) It can be shown analytically that the long term probability of winning the dice game you have programmed in PA 8-3 is.4929293. Extend that program you wrote to run a large number of turns and calculate the empirical (experimental) probability. 1,000,000 times through the for loop took about 2 seconds on a computer similar. to those in the classroom. If yours takes longer than 10 seconds there is probably something wrong in your program. It is a good idea to run your loop only 100 or so times the first few times through. Hint: cast your # of wins and losses as float so you don't run into problems with integer division. DACodeBlocks-EP CodeBlocks-EP1Marsh2050 bin\DebuglMarsh2050.exe How many turns would you like? 1000000 No. of Wins:492742 No. of Losses: 507258 Experimental probability of winning: 0.492742

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions

Question

6. Be able to choose and prepare a training site.

Answered: 1 week ago