fork download
  1. //Roman Lara Delgado CSC5 Chapter 7, P.444, #3
  2. //
  3. /*******************************************************************************
  4. *
  5. * Report Salsa Sales
  6. *_______________________________________________________________________________
  7. * This program calculates total jars sales of salsas then determines the salsas
  8. * with the highest and lowest sales.
  9. * ______________________________________________________________________________
  10. * INPUT
  11. * jars[] : The amount of jars sold for each salsa.
  12. *
  13. * OUTPUT
  14. * totalSales : amount of total salsa jar sales
  15. * highestSalsaName : name of best selling salsa
  16. * lowestSalsaName : ame of least selling salsa
  17. *******************************************************************************/
  18. #include <iostream>
  19. #include <string>
  20. using namespace std;
  21.  
  22. int main ()
  23. {
  24. /***************************************************************************
  25. * CONSTANTS
  26. * -------------------------------------------------------------------------
  27. * SALSAS : Number of different salsas
  28. * ************************************************************************/
  29. //Initialize Program Constants
  30. const int SALSAS = 5; //CONSTANT - Number of different salsas
  31.  
  32. //Delcare Program Variables
  33. int jars[SALSAS]; //INPUT - jar sales for each salsa
  34.  
  35. //Salsa Names
  36. string nameSalsa[SALSAS] = {"mild", "medium", "sweet", "hot", "zesty"};
  37.  
  38. int totalSales = 0; //CALC - amount of total salsa jar sales
  39. int highestSalsa; //CALC - highest salsa jars sold
  40. int lowestSalsa; //CALC - highest salsa jars sold
  41. string highestSalsaName; //OUTPUT - name of best selling salsa
  42. string lowestSalsaName; //OUTPUT - name of least selling salsa
  43.  
  44. //Input Salsa Jar Sales
  45. for (int count = 0; count < SALSAS; count++)
  46. {
  47. cout << "Enter number of " << nameSalsa[count];
  48. cout << " salsa jars sold last month: ";
  49. cin >> jars[count];
  50. cout << endl;
  51. totalSales += jars[count];
  52. }
  53.  
  54. highestSalsaName = nameSalsa[0];
  55. highestSalsa = jars[0];
  56.  
  57. //Determine Highest Selling Salsa
  58. for (int count = 1; count < SALSAS; count++)
  59. {
  60. if (jars[count] > highestSalsa)
  61. {
  62. highestSalsa = jars[count];
  63. highestSalsaName = nameSalsa[count];
  64. }
  65. }
  66.  
  67. lowestSalsaName = nameSalsa[0];
  68. lowestSalsa = jars[0];
  69.  
  70. //Determine Lowest Selling Salsa
  71. for (int count = 1; count < SALSAS; count++)
  72. {
  73. if (jars[count] < lowestSalsa)
  74. {
  75. lowestSalsa = jars[count];
  76. lowestSalsaName = nameSalsa[count];
  77. }
  78. }
  79.  
  80. cout << endl;
  81.  
  82. //Output Total Individual Jars Sales Last Month
  83. for (int count = 0; count < SALSAS; count++)
  84. {
  85. cout << "Total amount of " << nameSalsa[count];
  86. cout << " salsa jars sold last month was " << jars[count] << ".";
  87. cout << endl;
  88. }
  89.  
  90. //Output Total Jars Sales Last Month
  91. cout << endl;
  92. cout << "The total amount of salsa jars sold last month was " << totalSales;
  93. cout << " jars." << endl;
  94.  
  95. //Output Best Selling Salsa
  96. cout << "The best selling salsa in the last month was " << highestSalsaName;
  97. cout << " with " << highestSalsa << " jars sold." << endl;
  98.  
  99. //Output Lowest Selling Salsa
  100. cout << "The lowest Salsa sold in the last month was " << lowestSalsaName;
  101. cout << " with " << lowestSalsa << " jars sold." << endl;
  102.  
  103. return 0;
  104. }
Success #stdin #stdout 0.01s 5304KB
stdin
273
3598
235
4566
3442
stdout
Enter number of mild salsa jars sold last month: 
Enter number of medium salsa jars sold last month: 
Enter number of sweet salsa jars sold last month: 
Enter number of hot salsa jars sold last month: 
Enter number of zesty salsa jars sold last month: 

Total amount of mild salsa jars sold last month was 273.
Total amount of medium salsa jars sold last month was 3598.
Total amount of sweet salsa jars sold last month was 235.
Total amount of hot salsa jars sold last month was 4566.
Total amount of zesty salsa jars sold last month was 3442.

The total amount of salsa jars sold last month was 12114 jars.
The best selling salsa in the last month was hot with 4566 jars sold.
The lowest Salsa sold in the last month was sweet with 235 jars sold.