fork download
  1. //Amari Mosley CSC5 Chapter 7, P. 444, #3
  2. //
  3. /**************************************************************
  4.  *
  5.  * CALCULATE MONTHLY SALSA SALES
  6.  * ____________________________________________________________
  7.  * This program computes the total sales, highest selling, and lowest selling
  8.  * salsas from a selection of 5 salsa flavors.
  9.  *
  10.  * Computation is based on the formula:
  11.  * TotalSales += sales[]
  12.  * ___________________________________________________________
  13.  * INPUT
  14.  * Number of salsa types (1,...,N)
  15.  * Sales of each salsa type (number of jars)
  16.  *
  17.  * OUTPUT
  18.  * TotalSales: Monthly total salsa sales (jars)
  19.  * HighestSales: Best selling Salsa type (number of jars sold)
  20.  * LowestSales: Worst selling Salsa type (number of jars sold)
  21.  *
  22.  **************************************************************/
  23. #include <iostream>
  24. #include <string>
  25. using namespace std;
  26.  
  27. int main() {
  28. const int SIZE = 5;
  29. string SalsaNames[SIZE] = { "mild", "medium", "sweet", "hot", "zesty" };
  30. int sales[SIZE];
  31. int TotalSales = 0;
  32. int HighIndex = 0;
  33. int LowIndex = 0;
  34.  
  35. cout << "Enter the number of jars sold for each salsa type last month:\n";
  36.  
  37. for (int count = 0; count < SIZE; count++) {
  38. do { // Prompts user to enter sale numbers
  39.  
  40. cout << SalsaNames[count] << ": ";
  41. cin >> sales[count];
  42.  
  43. if (sales[count] < 0) { // Input Validation
  44. cout << "Error: Jars sold cannot be negative. Please try again.\n";
  45. }
  46. } while (sales[count] < 0); // Input Invalid then run loop again
  47.  
  48. TotalSales += sales[count];
  49. }
  50. cout << "Line #50: " << TotalSales << endl;
  51. // exit(0);
  52.  
  53. for (int count = 1; count < SIZE; count++) {
  54. // Calculates Highest and Lowest Sales
  55. if (sales[count] > sales[HighIndex]) {
  56. HighIndex = count;
  57. }
  58. if (sales[count] < sales[LowIndex]) {
  59. LowIndex = count;
  60. }
  61. }
  62. // Output Complete Sales Report
  63. cout << endl;
  64. cout << "\n MONTHLY SALSA SALES REPORT \n";
  65. cout << "Total Sales: " << TotalSales << " jars\n";
  66. cout << "Highest Selling Product: " << SalsaNames[HighIndex] << " (" << sales[HighIndex] << " jars)\n";
  67. cout << "Lowest Selling Product: " << SalsaNames[LowIndex] << " (" << sales[LowIndex] << " jars)\n";
  68. }
Success #stdin #stdout 0s 5328KB
stdin
26
75
13
54
43
stdout
Enter the number of jars sold for each salsa type last month:
mild: medium: sweet: hot: zesty: Line #50: 211


 			MONTHLY SALSA SALES REPORT 
Total Sales: 211 jars
Highest Selling Product: medium (75 jars)
Lowest Selling Product: sweet (13 jars)