Question
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++
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.492742Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started