//Cameron Pham CS1A Chapter 7, p. 444, #3
//
/******************************************************************************
* TRACK SALES OF SALSA
* ______________________________________________________________________________
* This program accepts an integer value for the number of salsa jars sold. It
* then determines the number of jars sold for each type of salsa and the total
* number of jars sold. It determines the greatest amount of jars sold for one
* type and the least amount of jars sold for one type.
* ______________________________________________________________________________
* INPUT
* Jars // Number of jars sold
* Salsa // Type of salsa being sold
*
* OUTPUT
* Total // Total number of jars sold across all salsas
* salsaSales // Number of jars sold for each salsa type
* Greatest // The type of salsa with the most amount sold
* Least // The type of salsa with the least amount sold
*******************************************************************************/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
// Create an array containing the five salsa names.
// The names are initialized when the array is created.
string salsaNames[5] =
{
"Mild", "Medium", "Sweet", "Hot", "Zesty"
};
// Create a parallel array to store the number of jars sold
const int SIZE = 5;
int jarsSold[SIZE];
// Store the total number of jars sold
int totalSales = 0;
// Store the array positions of the highest and lowest sales
int highestIndex = 0;
int lowestIndex = 0;
// Ask the user to enter the sales for each salsa type
for (int i = 0; i < SIZE; i++)
{
cout << "Enter the number of jars sold for "
<< salsaNames[i] << " salsa: ";
cin >> jarsSold[i];
// Validate the input so that sales cannot be negative
while (jarsSold[i] < 0)
{
cout << "Sales cannot be negative. "
<< "Enter the number of jars sold: ";
cin >> jarsSold[i];
}
// Add the current sales amount to the total
totalSales += jarsSold[i];
}
// Find the highest and lowest selling salsa types
for (int i = 1; i < SIZE; i++)
{
if (jarsSold[i] > jarsSold[highestIndex])
{
highestIndex = i;
}
if (jarsSold[i] < jarsSold[lowestIndex])
{
lowestIndex = i;
}
}
// Display the sales report.
cout << "\n--- Salsa Sales Report ---\n";
cout << left << setw(20) << "Salsa Type"
<< setw(15) << "Jars Sold" << endl;
cout << "-----------------------------------\n";
for (int i = 0; i < SIZE; i++)
{
cout << left << setw(20) << salsaNames[i]
<< setw(15) << jarsSold[i] << endl;
}
// Display the total sales
cout << "\nTotal jars sold: " << totalSales << endl;
// Display the highest selling salsa
cout << "Highest selling salsa: "
<< salsaNames[highestIndex] << endl;
// Display the lowest selling salsa
cout << "Lowest selling salsa: "
<< salsaNames[lowestIndex] << endl;
return 0;
}