fork download
  1. //Devin Scheu CS1A Chapter 6, P. 369, #3
  2. //
  3. /**************************************************************
  4. *
  5. * DETERMINE WINNING DIVISION BY SALES
  6. * ____________________________________________________________
  7. * This program identifies the company division with the
  8. * highest quarterly sales among four divisions.
  9. * ____________________________________________________________
  10. * INPUT
  11. * divisionSales : The quarterly sales figure for each division
  12. *
  13. * OUTPUT
  14. * highestDivision : The name and sales figure of the division with the highest sales
  15. *
  16. **************************************************************/
  17.  
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string>
  21.  
  22. using namespace std;
  23.  
  24. // Function to get sales for a division
  25. double getSales(string divisionName) {
  26. double sales;
  27. cout << "Enter the quarterly sales for " << divisionName << ": $";
  28. cin >> sales;
  29. while (sales < 0.0) {
  30. cout << "\nError: Please enter a non-negative amount: $";
  31. cin >> sales;
  32. }
  33. cout << sales << endl;
  34. return sales;
  35. }
  36.  
  37. // Function to find the highest sales division
  38. void findHighest(double northeast, double southeast, double northwest, double southwest) {
  39. double highestSales = northeast;
  40. string highestDivision = "Northeast";
  41.  
  42. if (southeast > highestSales) {
  43. highestSales = southeast;
  44. highestDivision = "Southeast";
  45. }
  46. if (northwest > highestSales) {
  47. highestSales = northwest;
  48. highestDivision = "Northwest";
  49. }
  50. if (southwest > highestSales) {
  51. highestSales = southwest;
  52. highestDivision = "Southwest";
  53. }
  54.  
  55. cout << left << setw(25) << "Highest Grossing Division:" << right << setw(15) << highestDivision << endl;
  56. cout << left << setw(25) << "Sales Amount:" << right << setw(15) << "$" << fixed << setprecision(2) << highestSales << endl;
  57. }
  58.  
  59. int main () {
  60.  
  61. //Variable Declarations
  62. double northeastSales; //INPUT - The quarterly sales figure for Northeast division
  63. double southeastSales; //INPUT - The quarterly sales figure for Southeast division
  64. double northwestSales; //INPUT - The quarterly sales figure for Northwest division
  65. double southwestSales; //INPUT - The quarterly sales figure for Southwest division
  66. string highestDivision; //OUTPUT - The name and sales figure of the division with the highest sales
  67.  
  68. //Get Sales for Each Division
  69. northeastSales = getSales("Northeast");
  70. southeastSales = getSales("Southeast");
  71. northwestSales = getSales("Northwest");
  72. southwestSales = getSales("Southwest");
  73.  
  74. //Separator and Output Section
  75. cout << "-------------------------------------------------------" << endl;
  76. cout << "OUTPUT:" << endl;
  77.  
  78. //Find and Display Highest Sales
  79. findHighest(northeastSales, southeastSales, northwestSales, southwestSales);
  80.  
  81. } //end of main()
Success #stdin #stdout 0.01s 5320KB
stdin
50
40
70
60
stdout
Enter the quarterly sales for Northeast: $50
Enter the quarterly sales for Southeast: $40
Enter the quarterly sales for Northwest: $70
Enter the quarterly sales for Southwest: $60
-------------------------------------------------------
OUTPUT:
Highest Grossing Division:      Northwest
Sales Amount:                          $70.00