/* Winning Division - This program determines which of a company's four
divisions (Northeast, Southeast, Northwest, and Southwest) had the
greatest sales for a quarter. It includes the following two functions
which are called by main.
* double getSales()
* void findHighest()
Input Validation: No dollar amounts less than $0.00 are accepted. */
#include "Utility.h"
/* Prototypes: Get sales, Find highest */
double getSales(double, string);
void findHighest(double, double, double, double);
int main()
{
/* Variables: Divisions (North-East, South-East,
North-West, South-West) */
double divisionNE = 0.0,
divisionSE = 0.0,
divisionNW = 0.0,
divisionSW = 0.0;
/* Display: Information */
cout << "\t\tIshikawa Fruit Company - Winning Sales Division\n\n"
<< "Every year we determine our winning sales division based\n"
<< "on the highest total sales figures per quarter. Enter\n"
<< "the sales figures for each of our four divisions, to\n"
<< "find out which division has won in this quarter.\n\n";
/* Call: getSales (NE, SE, NW, SW) */
divisionNE = getSales(divisionNE, "Division North-East");
divisionSE = getSales(divisionSE, "Division South-East");
divisionNW = getSales(divisionNW, "Division North-West");
divisionSW = getSales(divisionSW, "Division South-West");
/* Call: getHighest */
findHighest(divisionNE, divisionSE, divisionNW, divisionSW);
pauseSystem();
return 0;
}
/* **********************************************************
Definition: getSales
getSales 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 is called once for each division.
********************************************************** */
double getSales(double salesTotal, string regionName)
{
/* Get: Sales total */
cout << "Sales Total " << regionName << "$ ";
cin >> salesTotal;
/* Validation: While salesTotal is 0 or negative, a message
is displayed asking the user to repeat his or her
input */
while (salesTotal <= 0)
{
cout << "\nThe value you entered for sales total could\n"
<< "not be accepted because it was 0 or negative.\n"
<< "Please repeat your input: ";
cin >> salesTotal;
}
return salesTotal;
}
/* **********************************************************
Definition: findHighest
findHighest is passed the four sales totals. It determines
which is the largest and prints the name of the high grossing
division, along with its sales figure.
********************************************************** */
void findHighest(double highNE, double highSE,
double highNW, double highSW)
{
/* Variable: Highest, initialized to highNE for comparison */
double highest = highNE;
/* Variable: Region name */
string divisionName = " ";
/* Conditional Statements Tier 1: Determine which division has
had the highest sales this quarter */
highest = highSE > highest ? highSE : highest;
highest = highNW > highest ? highNW : highest;
highest = highSW > highest ? highSW : highest;
/* Conditional Statements Tier 2: Assign the division names */
divisionName = highNE == highest ? "North-East Division" : divisionName;
divisionName = highSE == highest ? "South-East Division" : divisionName;
divisionName = highNW == highest ? "North-West Division" : divisionName;
divisionName = highSW == highest ? "South-West Division" : divisionName;
/* Set up: Numeric output formatting */
cout << fixed << showpoint << setprecision(2);
/* Display: The company division with the highest sales */
cout << "\nY. Sato, our most honorable Company President is proud\n"
<< "to proclaim our successful " << divisionName
<< " with a\n"
<< "Sales Total of: $" << highest
<< " the winner of this quarter's\n"
<< "Grand Prize in our traditional sales competition!\n";
}
Monday, January 2, 2017
Programming Challenge 6.3 - Winning Division
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment