lab assignment help (functions & arrays)

I need some help with this C++ assignment. Any help would be appreciated, thank you!

Assignment:

You are provided a function (RollDice) that will give the result of rolling 1 dice. You are to develop a function that will roll n dice many times and gather information about the results. You are to keep a count of how many times each possible value of summing the n dice (n to 6*n) occurs. You should use an array to keep track of the counts. So, if rolling 1 dice, you will keep in the array how many times each value 1 through 6 occurred. If 2 dice were rolled, you will keep in the array how many times each value 2 through 12 occurred. It is suggested to use the value on the dice as the index to the array where the count is kept. Note that this means there will be wasted entries in the array as not all values are
possible, for instance you can never roll a 0.

1. Create a function to run the experiment that accepts as parameters: the array where the results will be placed, the number of dice, and the number of times to run the experiment. This allows us to use the computer to run a large number of experiments rather than manually rolling the dice. The function should 1st initialize all entries in the results array to 0. It should then run the experiment n times, each time calling the RollDice time for each dice in a roll, so if there are 2 dice, it should be called 2 times. Those values are summed to get the value of the roll. The value should then be used to update the count in the array of how many times that value has
been rolled.

2. Create a function that prints the results to a file. The function should take as parameters the array holding the results, the number of dice, and a string containing the name of the output file. It should write the results out in 2 columns separated by a comma. The 1st column should have the roll value (only print valid values for the number of dice used). The second column should have the number of times that value was observed.

3. Main should set up and run an experiment. You need to declare a constant defining the number of dice to be rolled each time. Using this constant, declare an array to hold the results of the experiment, making sure you have an appropriate number of entries in the array. Then you should call your function to run the experiment.

Also, I am to test the lab with 1, 2, 3, 4, and 10 dice using a large number of rolls for each experiment (like 1,000,000 for example). Then, plot the resulting data in Excel as a bar graph.

This is what I have so far. Any corrections/tips would be highly appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 #include "Dice.h"
#include<random>

using namespace std;

int RollDie()
{
	static std::random_device rd;
	static std::default_random_engine engine(rd());
	static std::uniform_int_distribution<int> uniform_dist(1, 6);

	return uniform_dist(engine);
}

void array(int results[], int num)
{
	for (int i = 0; i < num; i++)
	{
		results[i] = 0;
	}
}

void experiment(int results[], int dice, int runs)
{
	for (int r = 0; r < runs; r++)
	{
		int sum = 0;
			for (int d = 0; d < dice; d++)
			{
				sum = sum + RollDie();
				results[sum]++;
			}
	}
} 
glixy wrote:
This is what I have so far.


Nah. You took it from here, didn't you?
http://www.cplusplus.com/forum/general/264686/#msg1140383
Topic archived. No new replies allowed.