fork download
  1. //Ryan Robateau CSC5 Chapter 7, P. 444, #3
  2. //
  3. /*******************************************************************************
  4.  * Compute Chip and Salsa Sales
  5.  * _____________________________________________________________________________
  6.  * This program prompts the user for the number of jars sold
  7.  * for different types of salsas. The program then produces a
  8.  * report displaying sales for each salsa type, total sales,
  9.  * and the names of the highest selling and lowest selling
  10.  * products.
  11.  * _____________________________________________________________________________
  12.  ******************************************************************************/
  13. #include <iostream>
  14. #include <string>
  15. #include <iomanip>
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20.  
  21. const int SALSA_TYPES = 5;
  22. int jars[SALSA_TYPES]; // INPUT - Jars Sold
  23. int jarsTotal; // OUTPUT - Total of all jars sold
  24. int jarsMax; // OUTPUT - Most Jars sold
  25. int jarsMin; // OUTPUT - Least Jars sold
  26. int count;
  27. string salsaNames[SALSA_TYPES] = { "Mild",
  28. "Medium",
  29. "Sweet",
  30. "Hot",
  31. "Zesty"};
  32. string salsaMost = salsaNames[0];
  33. string salsaLeast = salsaNames[0];
  34.  
  35. for (count = 0; count < SALSA_TYPES; count++)
  36. {
  37. cout << "Enter number of jars sold for " << salsaNames[count] << ":";
  38. cout << endl;
  39. cin >> jars[count];
  40.  
  41. while (jars[count] < 0)
  42. {
  43. cout << endl << "<ERROR: Please input a value greater than 0>";
  44. cout << endl << endl;
  45. cout << "Enter the number of jars for " << salsaNames[count]
  46. << ": " << endl;
  47. cin >> jars[count];
  48. }
  49. }
  50.  
  51. for (count = 0; count < SALSA_TYPES; count++)
  52. jarsTotal += jars[count];
  53.  
  54. jarsMax = jars[0];
  55. for (count = 0; count < SALSA_TYPES; count++)
  56. {
  57. if (jars[count] > jarsMax)
  58. {
  59. jarsMax = jars[count];
  60. salsaMost = salsaNames[count];
  61. }
  62. }
  63.  
  64. jarsMin = jars[0];
  65. for (count = 0; count < SALSA_TYPES; count++)
  66. {
  67. if (jars[count] < jarsMin)
  68. {
  69. jarsMin = jars[count];
  70. salsaLeast = salsaNames[count];
  71. }
  72. }
  73.  
  74. // OUTPUT RESULTS
  75. cout << endl << "SALSA SALES" << endl;
  76. cout << "---------------------" << endl;
  77. for (count = 0; count < SALSA_TYPES; count++)
  78. {
  79. cout << left << setw(11) << salsaNames[count]
  80. << ": " << jars[count] << " jars" << endl;
  81. }
  82. cout << "Total sales: " << jarsTotal << " jars" << endl;
  83. cout << "Highest selling salsa: " << salsaMost << endl;
  84. cout << "Lowest selling salsa: " << salsaLeast;
  85. return 0;
  86. }
Success #stdin #stdout 0s 5312KB
stdin
1
2
3
4
5
stdout
Enter number of jars sold for Mild:
Enter number of jars sold for Medium:
Enter number of jars sold for Sweet:
Enter number of jars sold for Hot:
Enter number of jars sold for Zesty:

SALSA SALES
---------------------
Mild       : 1 jars
Medium     : 2 jars
Sweet      : 3 jars
Hot        : 4 jars
Zesty      : 5 jars
Total sales: 15 jars
Highest selling salsa: Zesty
Lowest selling salsa: Mild