Question
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
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