Microsoft Word - Document1
Execute to let user enter some prices to display their highest price, total sum, average,
and the price that is most close to the average.
1. The program's main function must call the following three functions in the given
order. No any external variables are used by main.
• void get_prices(int *, double );
• double *max_avg_sum(double , int, double *, double *);
• void near_avg(double , int, double, double *);
2. get_prices first prompts a message "How many prices will you enter?" and
ased on this input number, it reads all prices into a double type a
ay, which is
defined by the 2nd parameter of this function. The price values could be positive,
negative, or zero, possibly duplicated but each must be entered with a space to
separate it from the previous price (e.g., XXXXXXXXXX XXXXXXXXXXThe
total number of prices is made available to the main via the first parameter of this
function, which is an int pointer (i.e., it's passed by reference or address). **This
function assumes both inputs from user are always valid.
3. max_avg_sum is the most complicated function of this program. The main of
the program calls it to find the highest or maximum value, the total sum, and the
average of prices given in its first parameter, which is a double type a
2nd parameter is a passed-by-value integer, which tells the function the total
number of prices (i.e., the size of the a
ay) so it can easily calculate the desired
• Among the three calculated data, total sum and average are made
available to the main via the last two parameters of this function. They
oth are declared to be a double type pointer.
• The last calculated data is the highest or maximum value of prices.
Whichever item in the a
ay is determined to have this highest value, its
address is expected to be returned by this function to the caller (i.e.,
main). This satisfies the function's return type, which is a double type
4. Once the main gets the highest price, the total sum of all prices, and their
average, it prints them as shown in the above screenshot. All price value must be
printed with '$' and only two decimal digits.
5. near_avg is void function. main calls it at the end of the program to find which
price in the input a
ay is most close to the price average. Like the previous
function, it knows all prices and the total number of prices via its first two
parameters. Instead of re-calculating the price average, it receives the average
from the caller via its third parameter. Once it compares all prices to the average
and find the one nearest to the average, this price value is made available to the
main via the last parameter, which is a double type pointer. Once this
function returns to main, main needs to display the price nearest to the average
as shown in the above screenshot.