Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a c++ program that will roll a die a large number of times and calculate the probability of rolling each number. Use an array

Write a c++ program that will roll a die a large number of times and calculate the probability of rolling each number.

Use an array of size 7 in your program

The seventh slot (index 6) will hold the total number of times a 6 is rolled.

The second slot (index 1) will hold the total number of times a 1 is rolled. The first slot (index 0) will not be used

The content in index 1 is a counter representing the number of times a 1 was rolled. It should be set to zero at the beginning. Each time a 1 is rolled, it should be incremented (use the increment operator to do this. See the example below).

int ar[3]; ar[1] = 0; ar[1]++; //incrementcout << ar[1];ashows 1

int main()

{

srand(time(0)); //ensures random() generates a different sequence of random numbers in each run

const int SIDES = 6; //the number of sides on a dieconst int NUM_ROLLS = 100; //the number of rolls

//declare an array that will contain counters.

Requirement: You need to use SIDES.//initialize the array here

Requirement: You need to use SIDES.

//roll a die NUM_ROLLS times and keep track of how many times each number was rolled

Requirement: You must use the increment operator. Dont use if else-ifs or switch

//Show the contents of the array (the number of times each number was rolled) along with the probability of rolling each number. Don't show the content in index 0.

return 0;

}

sample runs for 100 rolls

1: 12 12.0000%

2: 19 19.0000%

3: 18 18.0000%

4: 11 11.0000%

5: 19 19.0000%

6: 21 21.0000%

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

10-4 How has e-commerce affected business-to-business transactions?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

5. To determine the financial benefits and costs of the program.

Answered: 1 week ago