I'm having an error on my displayResult function. In the line:

cout << setw(17) << static_cast<int>(exptRoll[value-1] * intRepeats);

I have a C2109 error (subscript requires array or pointer type. Does anyone how to solve this problem?

void displayResult(const int arraySize, double frequency[], double expected[], int intRepeats, double exptRoll)
{
	cout << "\nGenerating rolls... \n " << endl;			//message 
	cout << "\nFinal statistics: \n " << endl;			


	//Output the results of the dice rolling (sum, frequency, actual percent and expected rolls, expected percent)  
	cout << ""  << endl;																//begin the header 
	cout << "Point" << setw(17) << "Number of Rolls" << setw(17) << "Actual Percent" 
					<< setw(17) << "Expected Rolls" << setw(17) << "Expected Percent" << endl;

	for (int value = 2; value < arraySize; value++)										//begin generating the table
  	{
		cout << setw(5) << value  ;														//value points	
		cout << setw(17) << static_cast<int>(frequency[value]) ;						//actual rolls
		cout << setw(16) << ((frequency[value]/intRepeats)*100) << "%" ;				//actual percentage
		cout << setw(17) << static_cast<int>(exptRoll[value-1] * intRepeats);			//expected rolls
		cout << setw(16) << setprecision (3) << expected[value]<< "%"  << endl;			//expected percentage 
	}

}

exptRoll is not an array. Its a double that you passed into displayResult(). I see that expected is an array and it probably had what the calculated expected value should be for rolling dice. I think that exptRoll might not be needed. If you have the expected percentage for each of the numbers than you should just have to multiple the number of rolls by the expected percentage to get expected rolls. If intRepeats is the number of rolls in you experiment.
What is exptRoll supposed to be and should you have one for each number rolled?

exptRoll is not an array. Its a double that you passed into displayResult(). I see that expected is an array and it probably had what the calculated expected value should be for rolling dice. I think that exptRoll might not be needed. If you have the expected percentage for each of the numbers than you should just have to multiple the number of rolls by the expected percentage to get expected rolls. If intRepeats is the number of rolls in you experiment.
What is exptRoll supposed to be and should you have one for each number rolled?

exptRoll is the racial I stored in Array. The program was working before I change to functions

If exprRoll is an array then displayResult should give an error because you pass it as a double. But if an array then change the prototype in displayResult to have exptRoll as double exptRoll[].

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.