I've been trying to do this problem for awhile now, but im not getting any luck. im just not completely understanding how single dimensional arrays work.
any help would be great
here's what i have so far, and then the problem is below.
include <iostream>
include <iomanip>
using namespace std; const double ARRAY_SIZE = 100;
void getElements(double arr[], int SIZE) {
for(int i = 0; i < SIZE;i++)
arr[i] = (rand() % 51) + 25;
} double mean(double arr[], int SIZE) {
double arrAvg = 0;
double total = 0;
for(int i = 0; i < ARRAY_SIZE; i++)
{
total +=arr[i];
}
arrAvg = total / ARRAY_SIZE;
return mean; } int getArray(double arr[], int size) {
cout << "Enter the Elements of the Array: \ ";
int i = 0;
for(i = 0; i < size; i++)
{
cin >> arr[i];
if(arr[i] == -1)
return i;
}
return i;
} int main() {
int arr[ARRAY_SIZE];
double size = getArray(arr, ARRAY_SIZE);
getElements( arr, size);
cout<<"The arithmetic mean of the array is: \ "<<mean(arr,size)<<endl;
return 0;
}
Write a program that consists of 3 functions. The function getElements() will be passed an array and the size of the array. The number of elements in the array will be supplied by the user in main() but may be up to 100. getElements() will populate the array with elements between the values of 25 and 75 inclusive using the random number generator. The function mean( ) will be passed the array with random integers created by getElements() and will pass back the arithmetic mean (the “average” – the sum of all the numbers divided by the number of elements – this will be a double) of the numbers in the array. The function main( ) will get the size of the array from the user and then call getElements(). main( ) will then call the function mean( ) to calculate the arithmetic mean; that number will be passed back to main( ) and assigned to a variable. main( ) will then display the arithmetic mean on the screen with an appropriate label.