I have the following question I need help with completing
Write a program that calcs the average of the four quarterly sales of a company and displays both the highest sales figure as well as the average sales figure for the year. For example if the user enters these values:
458.60 , 430.00, 376.70 and 246.30
the output will be:
The highest sales figure is R458.60 with an average of R377.90
to get the value of R377.90, the four values are added and divided by 4.
it should include the following functions, which are called by the main function:
a) A float function getSales to ask the user for a sales figure, validate it and return the sales figure. The function should be called by the main function once for each of the four quarterly sales figures to be entered. Validate the input so that the program does not accept amounts less than 0.
b) A float function findHighest that is passed the four sales figures, and that then determines and returns the highest sales figure.
c) A float function calcAverage that is passed the four sales figures, and that then determines and returns the average sales figure.
d) A void function displayOutput that is passed the highest sales figure and the average sales; it then displays the highest sales figure as well as the average sales figure, to two decimal digits after the decimal point.
the incomplete program is below along with the data that must be used for the program.
*****data to use*****
sales 1 * 6565.76 * 2443.67 * 8010.20 * 7343.45
sales 2 * 6653.80 * 3843.80 * 8444.80 * 6943.45
sales 3 * 7233.40 * 5232.68 * 8123.30 * 2645.12
sales 4 * 6543.00 * 2843.65 * 7265.50 * 6388.30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
//This program displays the division with the highest sales figure.
#include <iostream>
using namespace std;
//You must add the four functions here
int main()
{
float sales1,
sales2,
sales3,
sales4;
float averageSales;
float highestSales;
for (int i = 0; i < 4; i++)
{
//Get the sales for each division.
sales1 = getSales();
sales2 = getSales();
sales3 = getSales();
sales4 = getSales();
//Find the highest of the four sales figures
highestSales = findHighest(sales1, sales2, sales3, sales4);
//Find the average of the four sales figures
averageSales = calcAverage(sales1, sales2, sales3, sales4);
//Display the highest sales figure as well as the average
displayOutput(highestSales, averageSales);
}
return 0;
} //End of main
|