Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Coding Help For the following program below, the code does not generate random numbers each time it is run differently. I am looking to

C++ Coding Help

For the following program below, the code does not generate random numbers each time it is run differently.

I am looking to run this code with different outputs everytime for the probability of winning losing.

Is there any way for this to be fixed?

#include

#include

#include

#include

#include

using namespace std;

int Roll();

int main()

{

int win = 0, loss = 0, point = 0;

int s_roll = 0, dice = 0;

double probability = 0;

srand(100);

srand(time(0));

for (int j = 1; j <= 10000; j++)

{

point = 0;

dice = Roll();

if (dice == 7 || dice == 11)

{

win++;

continue;

}

else if (dice == 2 || dice == 3 || dice == 12)

{

loss++;

continue;

}

else

{

do

{

s_roll = Roll();

if (s_roll == point)

{

win++;

break;

}

else if (s_roll == 7)

{

loss++;

break;

}

}

while(s_roll != point || s_roll != 7);

}

}

cout << "Player wins: " << win << " Times." << endl;

cout << "Player loses: " << loss << " Times." << endl << endl;

probability = ((double)(win) / (win + loss)) * 100;

cout << "Probability of winning is: " << probability << " % " << endl;

system("Pause");

return 0;

}

int Roll()

{

int f_Dice = 0, s_Dice = 0;

f_Dice = (rand() % 6) + 1;

s_Dice = (rand() % 6) + 1;

return f_Dice + s_Dice;

}

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions