Write a program that determines which of a company\'s eight divisions (North, So
ID: 3799633 • Letter: W
Question
Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast, Southeast, Northwest, Southwest) had the greatest sales for a quarter. It should include the following two functions which are called only by main.
double getSales() - it is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns it. It should be called once for each division. Negative dollar amounts are invalid.
void findHighest() - it is passed the eight sales amounts. It then determines which is the largest and prints the name of the high grossing division along with it's sales figure.
Do not accept dollar amounts less than 0
Do not use arrays
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <cstdlib>
double getSales();
void findHighest(double, double, double, double);
int main()
{
double Northeast, Southeast, Northwest, Southwest;
std::cout << "Enter the quarterly sales for Northeast Division: " << std::endl;
Northeast = getSales();
std::cout << "Enter the quarterly sales for Southeast Division: " << std::endl;
Southeast = getSales();
std::cout << "Enter the quarterly sales for Northwest Division: " << std::endl;
Northwest = getSales();
std::cout << "Enter the quarterly sales for Southwest Division: " << std::endl;
Southwest = getSales();
findHighest(Northeast, Southeast, Northwest, Southwest);
return 0;
}
double getSales()
{
double sales;
std::cin >> sales;
if(sales < 0)
{
std::cout << " Error: Invalid figures please enter above zero" << std::endl;
exit(0);
}
return sales;
}
void findHighest(double Northeast, double Southeast, double Northwest, double Southwest)
{
if (Northeast > Southeast && Northeast > Northwest)
{
if(Northeast > Southwest)
{
std::cout << "The Northeast division had the greatest number of sales, $";
std::cout << Northeast << std::endl;
}
}
if (Southeast > Northeast && Southeast > Northwest)
{
if(Southeast > Southwest)
{
std::cout << "The Southeast division had the greatest number of sales, $";
std::cout << Southeast << std::endl;
}
}
if (Northwest > Northeast && Northwest > Southeast)
{
if(Northwest > Southwest)
{
std::cout << "The Northwest division had the greatest number of sales, $";
std::cout << Northwest << std::endl;
}
}
if (Southwest > Northeast && Southwest > Southeast)
{
if(Southwest > Northwest)
{
std::cout << "The Southwest divsion had the greatest number of sales, $";
std::cout << Southwest << std::endl;
}
}
}
-----------------------------------------------------------------------
Sample OutPut
Enter the quarterly sales for Northeast Division:
5000
Enter the quarterly sales for Southeast Division:
9000
Enter the quarterly sales for Northwest Division:
6000
Enter the quarterly sales for Southwest Division:
1000
The Southeast division had the greatest number of sales, $9000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.