When I run my program, I should be able to calculate the mean, however I keep getting the incorrect value and I am baffled as to why this is. My program is much longer than this but I am hoping to just find the reason why I am getting an incorrect value. Thanks.
//Calculate the mean
double mean (int userArray[], int numberElements)
{
double average = 0.0;
int sum = 0;
//Calculates the overall sum
for (int i = 0; i <= numberElements; i++)
{
sum = (sum + userArray[i]);
}//end for loop
(double)sum;
(double)numberElements;
average = (sum / numberElements);
cout << "The MEAN of the array is: " << average << endl;
return average;
}//end mean
//*****************************************************************
int main()
{
int numberElements, searchNumber, SIZEARRAY;
int userArray[SIZEARRAY];
cout << "Please enter the number of elements: ";
cin >> numberElements;
SIZEARRAY = (numberElements - 1);
//This loop allows the user to enter the array elements
for (int i = 0; i < numberElements; i++){
cout << "Please enter number: ";
cin >> userArray[i];
}//end for loop
//Prints the size of the array
cout << endl << "The size of the array is: " << numberElements << endl;
//Prints the array as entered by the user
cout << ("Original Array as entered: ");
for (int i = 0; i < numberElements; i++) {
cout << userArray[i] << " ";
}
//Finds the mean of the array
mean(userArray, numberElements);
system("pause");
return 0;
} //end main
I am only using my array and the number of array entrys. I've looked through this for about an hour and it keeps giving me bad values and I don't know why.