// Torrez, Elaine                                              CS1A Chapter 7, P. 444, #3
// *****************************************************************************************
// *                                   CHIPS AND SALSA                                      *
// *---------------------------------------------------------------------------------------*
// * This program tracks monthly jar sales for five salsa types using parallel arrays.     *
// * It prompts for jars sold (no negatives), then reports per-item sales, total sales,    *
// * and the highest- and lowest-selling product names (ties supported).                   *
// *                                                                                       *
// * INPUT:                                                                                *
// *     names[5]  : {"mild","medium","sweet","hot","zesty"}                               *
// *     sales[5]  : user-entered non-negative integers                                    *
// *                                                                                       *
// * OUTPUT:                                                                               *
// *     Per-salsa sales, total jars sold, highest seller(s), lowest seller(s).            *
// *****************************************************************************************
 
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
 
int main()
{
    /***** CONSTANTS *****/
    const int SIZE = 5;
 
    /***** PARALLEL ARRAYS *****/
    string names[SIZE] = {"mild", "medium", "sweet", "hot", "zesty"};
    int    sales[SIZE];
 
    /***** VARIABLES *****/
    int total = 0;
    int maxIndex = 0;
    int minIndex = 0;
 
    /***** INPUT SECTION *****/
    cout << "Enter the number of jars sold this month for each salsa type:\n";
    for (int i = 0; i < SIZE; i++)
    {
        cout << "  " << names[i] << ": ";
        cin >> sales[i];
 
        // Validate: no negative values
        while (sales[i] < 0)
        {
            cout << "    Invalid. Jars sold cannot be negative. Re-enter: ";
            cin >> sales[i];
        }
 
        total += sales[i];
 
        // Track min/max as we go (safe because i progresses from 0→4)
        if (sales[i] > sales[maxIndex]) maxIndex = i;
        if (sales[i] < sales[minIndex]) minIndex = i;
    }
 
    /***** OUTPUT SECTION *****/
    cout << "\n==================== CHIPS & SALSA REPORT ====================\n";
    cout << left << setw(12) << "Salsa" << right << setw(10) << "Jars Sold\n";
    cout << "--------------------------------------------------------------\n";
    for (int i = 0; i < SIZE; i++)
        cout << left << setw(12) << names[i] << right << setw(10) << sales[i] << "\n";
 
    cout << "--------------------------------------------------------------\n";
    cout << left << setw(12) << "TOTAL" << right << setw(10) << total << "\n";
 
    // Support ties by listing all matching the min/max values
    int maxVal = sales[maxIndex];
    int minVal = sales[minIndex];
 
    cout << "\nHighest selling product(s) (" << maxVal << "): ";
    bool first = true;
    for (int i = 0; i < SIZE; i++)
        if (sales[i] == maxVal) {
            cout << (first ? "" : ", ") << names[i];
            first = false;
        }
 
    cout << "\nLowest selling product(s) (" << minVal << "): ";
    first = true;
    for (int i = 0; i < SIZE; i++)
        if (sales[i] == minVal) {
            cout << (first ? "" : ", ") << names[i];
            first = false;
        }
 
    cout << "\n==============================================================\n";
 
    return 0;
}