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.  * salsa1: Salsa sales inputted by user through looping of array
  15.  * salsa2:
  16.  * salsa3:
  17.  * salsa4:
  18.  * salsa5:
  19.  *
  20.  * OUTPUT
  21.  * TotalSales: Total Salsa Sales for the month
  22.  * HighestSales: Highest selling Salsa flavor and its number of sales
  23.  * LowestSales: Lowest selling Salsa flavor and its number of sales
  24.  *
  25.  **************************************************************/
  26. #include <iostream>
  27. #include <string>
  28. using namespace std;
  29.  
  30. int main() {
  31. string SalsaNames[5] = { "mild", "medium", "sweet", "hot", "zesty" };
  32. int sales[5];
  33. int TotalSales = 0;
  34. int HighIndex = 0;
  35. int LowIndex = 0;
  36.  
  37. cout << "Enter the number of jars sold for each salsa type last month:\n";
  38.  
  39. for (int count = 0; count < 5; count++) {
  40. do { // Prompts user to enter sale numbers
  41.  
  42. cout << SalsaNames[count] << ": ";
  43. cin >> sales[count];
  44.  
  45. if (sales[count] < 0) { // Input Validation
  46. cout << "Error: Jars sold cannot be negative. Please try again.\n";
  47. }
  48. } while (sales[count] < 0); // Input Invalid then run loop again
  49.  
  50. TotalSales += sales[count];
  51. }
  52.  
  53. for (int count = 1; count < 5; 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 5308KB
stdin
26
75
13
54
43
stdout
Enter the number of jars sold for each salsa type last month:
mild: medium: sweet: hot: zesty: 

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