|
) If two dice are rolled. what is the probability of getting (1, 2), or (2, 3) and so on. We can answer
these questions analytically, but you need to write a code to verify the results. You can do that
following the steps:
a. Write a function rollDices that takes two parameters as output parameters (return values through
them). The function when called should return two random integers, each one between 1 and 6,
where each one represent the value of a rolled die.
Use the following code to generate a random number between a and b. We seed the random
number generator using srand function as shown below.#include <time.h>
#include <stdlib.h>
using namespace std;
//... you other functions ...
int main () {
// seed random number generator
srand ( time(NULL) );
// your other code here
// generate a random number between 1 and 10
int randomNumber = rand() % 10 + 1;
}
b. Write another function rollProb that takes a two dimensional array 6x6 and an integer
numberOfRolls. The function should call the rollDices function numberOfRolls times, and for
each call it should increment the corresponding cell in the array.
c. Your main program should prompt the user for the numberOfRolls and calls the function rollProb
and then prints the probability of obtaining each pair of values. Try it with 4 different number of
rolls: 100, 1000, 10000, 100000. I will explain it more in class.
|
|
|
|
|
Is it urgentz?
Really though, please see here[^] especially point #11.
|
|
|
|
|
Haiathem alhmoud wrote: ) If two dice are rolled. what is the probability of getting (1, 2), or (2, 3) and so on. 1/6 * 1/6
Haiathem alhmoud wrote: I will explain it more in class. So, what happened?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|