fork download
  1. //Castulo Jason Quintero CSC5 Chapter 6, P. 369, #3
  2. //
  3. /**************************************************************************
  4.  *
  5.  * Calculate Winning Division
  6.  * ________________________________________________________________________
  7.  * This program takes as user input the quartly sales from each
  8.  * division and determines which one had the most sales.
  9.  *
  10.  *
  11.  * Computation is based on formula:
  12.  * The findHighest function will compare the sales of each
  13.  * division and display the store that has the most sales.
  14.  * ________________________________________________________________________
  15.  * INPUT
  16.  * sales : The amount of sales made from a division
  17.  *
  18.  * OUTPUT
  19.  * shop1 : Sales made by the North East
  20.  * shop2 : Sales made by the South East
  21.  * shop3 : Sales made by the North West
  22.  * shop4 : Sales made by the South West
  23.  * The output will be which store made the most sales
  24.  * followed by the value of the sales made.
  25.  *
  26.  *************************************************************************/
  27.  
  28. #include <iostream>
  29. #include <iomanip>
  30. using namespace std;
  31.  
  32. double getSales(string);
  33. void findHighest(float, float, float, float);
  34.  
  35. int main()
  36. {
  37. // String variables to hold division names.
  38. string name1 = "North East";
  39. string name2 = "South East";
  40. string name3 = "North West";
  41. string name4 = "South West";
  42.  
  43. // Variables to hold the value of each division.
  44. float store1;
  45. float store2;
  46. float store3;
  47. float store4;
  48.  
  49. // Tells the user what will happen
  50. cout << "Enter the sales of each division and the division with the "
  51. << "most sales will be presented.\n";
  52.  
  53. // Function that is passed division name, validates, and returns the
  54. // value to the variable associated with the division.
  55. store1 = getSales(name1);
  56. store2 = getSales(name2);
  57. store3 = getSales(name3);
  58. store4 = getSales(name4);
  59.  
  60. // Function that is passed the values and checks to see which
  61. // division had the most sales.
  62. findHighest(store1, store2, store3, store4);
  63.  
  64. return 0;
  65. }
  66.  
  67. // User enters sales of each division and validates it.
  68. double getSales (string storename)
  69. {
  70. float sales;
  71.  
  72. cout << "Please enter quarterly sales for the " << storename << ": \n";
  73. cin >> sales;
  74. while (sales < 0)
  75. {
  76. cout << "Please enter a value greater than zero: ";
  77. cin >> sales;
  78. }
  79. return sales;
  80. }
  81.  
  82. // Determines which division has the highest sales.
  83. void findHighest (float shop1, float shop2, float shop3, float shop4)
  84. {
  85. if (shop1 > shop2 && shop1 > shop3 && shop1 > shop4)
  86. {
  87. cout << "Northeast has the most sales! Totaling to $" << shop1;
  88. }
  89. else if (shop2 > shop1 && shop2 > shop3 && shop2 > shop4)
  90. {
  91. cout << "Southeast has the most sales! Totaling to $" << shop2;
  92. }
  93. else if (shop3 > shop1 && shop3 > shop2 && shop3 > shop4)
  94. {
  95. cout << "Northwest has the most sales! Totaling to $" << shop3;
  96. }
  97. else
  98. {
  99. cout << "Southwest has the most sales! Totaling to $" << shop4;
  100. }
  101. }
Success #stdin #stdout 0.01s 5308KB
stdin
6000 1000 3000 5000
stdout
Enter the sales of each division and the division with the most sales will be presented.
Please enter quarterly sales for the North East: 
Please enter quarterly sales for the South East: 
Please enter quarterly sales for the North West: 
Please enter quarterly sales for the South West: 
Northeast has the most sales! Totaling to $6000