fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 7 P.444 #3
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Salsa Sales
  6.  * ____________________________________________________________________________
  7.  * This program will determine the sells for each salsa type: mild, medium,
  8.  * sweet, hot and zesty. The prgram will produce a report that displays the
  9.  * sales for each salsa type, the total amount of sales of all the salsas,
  10.  * and the names of the highest and lowest selling products.
  11.  * ____________________________________________________________________________
  12.  * Input
  13.  * SIZE :The amount of salsa options
  14.  * salsaNames :The options of salsas sold
  15.  * jarsSold :The amount of jars sold per option
  16.  * Output
  17.  * totalSales :Total amount of jars sold
  18.  * highest :The salsa option that was sold the most
  19.  * lowest :The salsa option that was sold the least
  20.  *****************************************************************************/
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24. int main() {
  25. //Data Dictionary
  26. const int SIZE = 5; //INPUT - The amount of salsa options
  27. string salsaNames[SIZE] = {"mild", "medium", "sweet", "hot", "zesty"};
  28. //INPUT - The options of salsas sold
  29. int jarsSold[SIZE]; //INPUT - The amount of jars sold per option
  30. int totalSales = 0; //OUTPUT - Total amount of jars sold
  31. int highest = 0; //OUTPUT - The salsa option that was sold the most
  32. int lowest = 0; //OUTPUT - The salsa option that was sold the least
  33.  
  34. //User Input
  35. cout << "Enter the number of jars sold for each type of salsa: " << endl;
  36. for(int i = 0; i < SIZE; i++){
  37. do{
  38. cout << salsaNames[i] << ": " << endl;
  39. cin >> jarsSold[i];
  40.  
  41. //Input Validation
  42. if(jarsSold[i] < 0){
  43. cout << "Error: Sales cannot be negative. Please re-enter." << endl;
  44. }
  45. } while(jarsSold[i] < 0);
  46. }
  47.  
  48. //Calculations
  49. totalSales = jarsSold[0];
  50. for(int i = 1; i < SIZE; i++){
  51. totalSales += jarsSold[i];
  52. if(jarsSold[i] > jarsSold[highest])
  53. highest = i;
  54. if(jarsSold[i] < jarsSold[lowest])
  55. lowest = i;
  56. }
  57.  
  58. //Display Results
  59. cout << "SALSA SALES REPORT: " << endl;
  60. for(int i = 0; i < SIZE; i++){
  61. cout << salsaNames[i] << ": " << jarsSold[i] << " jars sold" << endl;
  62. }
  63. cout << "Total sales: " << totalSales << " jars" << endl;
  64. cout << "Highest selling product: " << salsaNames[highest] << " (";
  65. cout << jarsSold[highest] << " jars)" << endl;
  66. cout << "Lowest selling product: " << salsaNames[lowest] << " (";
  67. cout << jarsSold[lowest] << " jars)" << endl;
  68. return 0;
  69. }
Success #stdin #stdout 0.01s 5320KB
stdin
5
7
10
9
13
stdout
Enter the number of jars sold for each type of salsa: 
mild: 
medium: 
sweet: 
hot: 
zesty: 
SALSA SALES REPORT: 
mild: 5 jars sold
medium: 7 jars sold
sweet: 10 jars sold
hot: 9 jars sold
zesty: 13 jars sold
Total sales: 44 jars
Highest selling product: zesty (13 jars)
Lowest selling product: mild (5 jars)