Void Functions in Die Simulator

I wrote a code to simulate a die rolling 3600 times and it works and everything, but we're supposed to use a void function in it, which I did not, simply because I don't know what part of my code should be in the void function, please help me out.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58


#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <ctime>	

using namespace std;

const int ArraySize = 7;

void percentdifference(double frequency[], int ArraySize);
 
int main()
{
	int answer;


    double frequency[ ArraySize ] = { 0 };	
    double expected[ ArraySize ] = {16.7, 16.7,16.7,16.7,16.7,16.7,16.7,};
    
    srand( time( NULL ) );
      

    for (int roll = 1; roll <= 36000; roll++)
    frequency[ (rand() % 6)+1]++;
       


    cout << "Sum of Die" << setw( 20 ) << "Number of Rolls" << setw( 20 ) << "Actual Percent"	
	     << setw( 20 ) << "Expected Percent" << endl;
    for (int face= 1; face< ArraySize; face++)
		cout << setw( 10 ) << face<< setw( 20 ) << frequency[ face] << setw( 20 )
		<< ( frequency[ face] / 36000 ) * 100 << setw( 20 ) << expected[ face] << endl;
		
	int die;
	double percentdiff;
	//call function
	percentdiff(frequency,7);
	

	system("PAUSE");
	return 0;
} 


void percentdiff(double frequency[], int ArraySize)
{
	
	for (int roll = 1; roll <= 36000; roll++)
    frequency[ (rand() % 6)+1]++;
       
	for(int face=1; face<ArraySize; face++)
		cout << "\n Percent difference of " << face<< " is " << abs((frequency[face]-10000)/10000)*100;

	return;
}



edit: No he didn't give an indication, the assignment wasn't in writing so I don't have word by word instructions just what I wrote down. I did just find that I need to calculate the percent difference, maybe use a void function for that?
Last edited on
You could just put the contents of main into the function, and then call the function from main... but you probably wouldn't get full credit for that. You could spice it up a bit by allowing the function to take an integer parameter, that defaults to 3600, for the number of times to roll the dice.
Did your professor give you any indication of what he wanted besides just a void function? If you have the assignment in his words, we can make sure you are doing exactly what he asked for full credit. If not, I would do what ModShop said, make a void function that takes an int for the number of dice rolls to simulate.
ok so I made a void function(I edited the original post to show this) but now it keeps telling me "the term does not evaluate to a function taking two arguments" and when I change it so it's one or no arguments, I get the same error
*der Simulator
The name of your function is void percentdiff(double frequency[], int ArraySize), but it's named void percentdifference(double frequency[], int ArraySize) above main.
Last edited on
Topic archived. No new replies allowed.