Description
The purpose of this challenge is to pass pointers as function parameters. This challenge illustrates the use of the dereferencing operator as well as the relationship between pointers and arrays.
Requirements
- Write a function void fill_array(int * array). This function will prompt the user to enter values that will be stored into the array parameter.
- Write a function void calc_stats(int * array, int * minimum, int * maximum, int * sum, double * average). This function will examine the array contents and figure out the smallest number, the largest number, the sum and average of all the element values.
- In main, declare the following integer variables minval, maxval, sum
- In main, declare a double variable called average
- In main, declare an array of integers called data to hold 10 values
- In main, call the fill_array() function passing in the data array. Then, call calc_stats() passing in the various parameters in the appropriate positions.
- Finally, display the values of the various declared variables to the user
Sample main()
int main() { int minval, maxval, sum; double average; int data[10]; // fill up an array asking the user to enter values // calculate stats on the array // display the stats to the user cout << minval << " " << maxval << " " sum << " " << average << endl; return 0; }
LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT
CATALOG ID: CPP-CHAL0017
Print Requirements