// Marvyn De La Torre CS1A Chapter 6, P.369, #3
//
/*************************************************************************
* DETERMINE WINNING DIVISION
*
* This program accepts quarterly sales amounts for the Northeast,
* Southeast, Northwest, and Southwest divisions. It determines and
* displays the division with the greatest sales amount.
*
* INPUT
* northeast : Sales for the Northeast division
* southeast : Sales for the Southeast division
* northwest : Sales for the Northwest division
* southwest : Sales for the Southwest division
*
* OUTPUT
* winningDivision : Name of the division with the greatest sales amount
* highestSales : The greatest sales amount
*************************************************************************/
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
using namespace std;
// Function Prototypes
double getSales(string division);
void findHighest(double northeast, double southeast, double northwest,
double southwest);
int main()
{
// Declare Variables
double northeast; // Sales for Northeast division
double southeast; // Sales for Southeast division
double northwest; // Sales for Northwest division
double southwest; // Sales for Southwest division
// Get Sales Totals
northeast = getSales("Northeast");
southeast = getSales("Southeast");
northwest = getSales("Northwest");
southwest = getSales("Southwest");
// Display the Winning Division
findHighest(northeast, southeast, northwest, southwest);
return 0;
}
/*************************************************************************
* getSales
* This function asks for and validates one division's sales amount.
*************************************************************************/
double getSales(string division)
{
double sales; // Sales amount entered by the user
cout << "Enter quarterly sales for the " << division << " division: $";
cin >> sales;
cout << endl;
// Validate Input
while (cin.fail() || sales < 0)
{
cout << "Enter a dollar amount of $0.00 or greater: $";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin >> sales;
}
return sales;
}
/*************************************************************************
* findHighest
* This function determines and displays the division with the highest
* quarterly sales amount.
*************************************************************************/
void findHighest(double northeast, double southeast, double northwest,
double southwest)
{
double highestSales; // Largest sales amount
string winningDivision; // Name of division with the largest sales amount
// Set Northeast as the starting highest value
highestSales = northeast;
winningDivision = "Northeast";
// Compare the remaining division totals
if (southeast > highestSales)
{
highestSales = southeast;
winningDivision = "Southeast";
}
if (northwest > highestSales)
{
highestSales = northwest;
winningDivision = "Northwest";
}
if (southwest > highestSales)
{
highestSales = southwest;
winningDivision = "Southwest";
}
// Display Result
cout << fixed << setprecision(2);
cout << "\nThe high-grossing division is the " << winningDivision
<< " division." << endl;
cout << "Its quarterly sales were $" << highestSales << "." << endl;
}