Answered step by step
Verified Expert Solution
Question
1 Approved Answer
// Chapter 5 homework solution: Sales #include #include using namespace std; // Function Prototype double caltotalSales(double, double); double calAverage(double, int); int main() { int years,
// Chapter 5 homework solution: Sales #include#include using namespace std; // Function Prototype double caltotalSales(double, double); double calAverage(double, int); int main() { int years, // The number of years totalQuarters; // The number of quarters double sales, totalSales = 0, // The total sales for all quarters average; // The average quarterly sales // Get the number of years. cout << "This program will calculate average sales over a " << "period of years. How many years do you wish to average? "; cin >> years; // Validate the number of years. while (years < 1) { cout << "Years must be at least one. Please re-enter: "; cin >> years; } for (int yearNumber = 1; yearNumber <= years; yearNumber++) { cout << " Year " << yearNumber << endl; // Get the sales amount for each quarter. for (int quarter = 1; quarter <= 4; quarter++) { cout << "sales amount for quarter " << setw(2) << quarter << "? "; cin >> sales; // Validate the sales amount. while (sales < 0) { cout << "Sales amount must be zero or greater. "; cout << "Sales amount for month " << quarter << "? "; cin >> sales; } // Get the total sales from funtion totalSales = caltotalSales(totalSales, sales); } } // Calculate the total number of quarters. totalQuarters = years * 4; // Get the average from average function average = calAverage(totalSales, totalQuarters); // Calculate the average sales amount. // Display the total sales amount for the period. cout << fixed << showpoint << setprecision(2); cout << " Over a period of " << totalQuarters << " quarters, " << totalSales < REWRITE THIS CODE USING ARRAY
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started