for (int count = 0; count < typesOfSalsa; count++)
{
cout<< "Enter the number of " <<salsa[count]<<" salsa jars sold in the past month: ";
cin>> numOfJarsSold[count];
while (numOfJarsSold[count]<0)
{
cout<< "Please enter a positive number: ";
cin>> numOfJarsSold[count];
}
totalJarsOfSalsa += numOfJarsSold[count];
}
for (int count = 0; count < typesOfSalsa; count++)
{
cout<< "Number of " <<salsa[count]<< " salsa jars sold in the past month: "<<numOfJarsSold[count]<<endl;
}
cout<<"Total number of jars sold in the past month: "<<totalJarsOfSalsa<<endl;
highest = numOfJarsSold[0];
for (int count =1; count < typesOfSalsa;count++)
{
if (numOfJarsSold[count]> highest)
{
highest = numOfJarsSold[count];
}
}
cout<<" The highest selling product is: "<<highest<<endl;
lowest = numOfJarsSold[0];
for (int count =1; count < typesOfSalsa;count++)
{
if (numOfJarsSold[count] <lowest)
{
lowest = numOfJarsSold[count];
}
}
cout<<" The lowest selling product is: "<<lowest<<endl;
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
const int typesOfSalsa = 5;
const int stringSize = 7;
char salsa [typesOfSalsa][stringSize] = {"mild","medium","sweet","hot","zesty"};
int numOfJarsSold [typesOfSalsa];
int totalJarsOfSalsa = 0;
int highest;
int lowest;
int highestNameNum;
int lowestNameNum;
for (int count = 0; count < typesOfSalsa; count++)
{
cout<< "Enter the number of " <<salsa[count]<<" salsa jars sold in the past month: ";
cin>> numOfJarsSold[count];
while (numOfJarsSold[count]<0)
{
cout<< "Please enter a positive number: ";
cin>> numOfJarsSold[count];
}
totalJarsOfSalsa += numOfJarsSold[count];
}
for (int count = 0; count < typesOfSalsa; count++)
{
cout<< "Number of " <<salsa[count]<< " salsa jars sold in the past month: "<<numOfJarsSold[count]<<endl;
}
cout<<"Total number of jars sold in the past month: "<<totalJarsOfSalsa<<endl;
highest = numOfJarsSold[0];
for (int count =1; count < typesOfSalsa;count++)
{
if (numOfJarsSold[count]> highest)
{
highest = numOfJarsSold[count];
highestNameNum = count;
}
}
cout<<" The highest selling product is "<< salsa[highestNameNum] << " : "<<highest<<endl;
lowest = numOfJarsSold[0];
for (int count =1; count < typesOfSalsa;count++)
{
if (numOfJarsSold[count] <lowest)
{
lowest = numOfJarsSold[count];
lowest = numOfJarsSold[count];
lowestNameNum = count;
}
}
cout<<" The lowest selling product is "<< salsa[lowestNameNum] << " : "<<lowest<<endl;
return 0;
}
Do you want to output product name like this??
Enter the number of mild salsa jars sold in the past month: 2
Enter the number of medium salsa jars sold in the past month: 4
Enter the number of sweet salsa jars sold in the past month: 3
Enter the number of hot salsa jars sold in the past month: 1
Enter the number of zesty salsa jars sold in the past month: 5
Number of mild salsa jars sold in the past month: 2
Number of medium salsa jars sold in the past month: 4
Number of sweet salsa jars sold in the past month: 3
Number of hot salsa jars sold in the past month: 1
Number of zesty salsa jars sold in the past month: 5
Total number of jars sold in the past month: 15
The highest selling product is zesty : 5
The lowest selling product is hot : 1