// Saliha Babar CS1A Chapter 7, Page 444, #3
//
/******************************************************************************
* DISPLAY SALES FOR EACH FLAOURS
* ____________________________________________________________________________
* This program accepts number of jars sold for each 5 flavours of salsa. This
* program then calculates the total jars sold as well as highest selling flavour
* and lowest selling flavour.
* ____________________________________________________________________________
* INPUT
* NumOfJars : number of jars sold for each flavour
*
* OUTPUT
* total : total jars sold
* highestFLavour : flavour wih most jars sold
* lowestFlavour : flavour with least jars sold
* ***************************************************************************/
#include <iostream>
using namespace std;
int main() {
const int TOTAL_FLAVOURS = 5;
string flavours[TOTAL_FLAVOURS] ={ "Mild" , "Medium" , "Sweet" , "Hot" , "Zesty"};
int NumOfJars[TOTAL_FLAVOURS];
int total;
int highest;
int lowest;
string highestFlavour;
string lowestFlavour;
total=0;
for (int i = 0; i < TOTAL_FLAVOURS ; i++)
{
cout << "Enter the number of jars sold for the type : " << flavours[i] ;
cin >> NumOfJars[i];
while (NumOfJars[i] < 0)
{
cout << "Enter positive number only\n";
cin >> NumOfJars[i];
}
cout << endl;
total += NumOfJars[i];
}
// Find the highest and the lowest value
highest = NumOfJars[0];
lowest = NumOfJars[0];
highestFlavour = "Mild";
lowestFlavour = "Mild";
for ( int i = 1 ; i < TOTAL_FLAVOURS ; i++)
{
if (NumOfJars[i] < lowest)
{
lowest = NumOfJars[i];
lowestFlavour = flavours[i];
}
if (NumOfJars[i] > highest)
{
highest = NumOfJars[i];
highestFlavour = flavours[i];
}
}
// Display the output
for (int i = 0 ; i < TOTAL_FLAVOURS ; i++)
{
cout << flavours[i] << " salsa. Number of jars sold : " << NumOfJars[i] << endl;
}
cout << "Total jars sold is " << total << endl;
cout << "The highest selling flavour is " << highestFlavour << endl;
cout << "The lowest selling flavour is " << lowestFlavour << endl;
return 0;
}