hi I have a problem finding the lowest and highest selling product in this question. Can you please help me ? this is what I have . It also wants me to display the name of the salsa not how many jars were sold how do I include that in the code. This is the question: Write a program that lets a maker of chips and salsa keep track of their sales for 5 different types of salsa: mild,medium,sweet,hot and zesty. It should use two parallel 5-element arrays: an array of strings that holds the 5 salsa names and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using an initialization list at the time the name array is created. The program should prompt the user to enter the number of jars sold for each type. Once this sales data has been entered, the program should produce a report that displays sales for each salsa type, total sales, and the names of the highest selling and lowest selling products.

#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;

	
	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];	
			}
		return highest;
	}
	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;
		}
	}
	
	
	
	return 0;
}

The easiest way to do this is make a for loop and initialize an integer to 0, everytime a number greater than your integer appears, set it to that number; if not, progress with the loop. At the end you should have to largest integer.

int high = 0;
int x;
int salsa[5];

for(x = 0; x < 5; x++) 
    if(salsa[x] > high)
       high = salsa[x];

cout<<high;

finding the lowest value is not much different, but you can easily figure it out from the snippet I gave you. Hope this helps :)

Thanks I fixed that. How do I get it to display the actual name of the highest and lowest selling products though?

Well I didn't really read your code thoroughly so I am going to assume you input the ammount in the order the flavors are listed; in which case, you just cout<<salsa[x] when high = numofjarssold[x].

I added two new loops to display the name of the lowest and highest selling products. does this look right? (it worked)

highest = numOfJarsSold[0];
	for (int count =0; count < typesOfSalsa ;count++)
	{
		if (numOfJarsSold[count]> highest)
		{	
			highest = numOfJarsSold[count];	
		}
		
	}
	for (int count =0; count < typesOfSalsa;count++)
	{
		if (highest ==numOfJarsSold[count])
		{
			cout<<" The highest selling product is: "<<salsa[count]<<endl;	
		}
	}

	lowest = numOfJarsSold[0];
	for (int count =0; count < typesOfSalsa;count++)
	{
		if (numOfJarsSold[count] <lowest)
		{	
			lowest = numOfJarsSold[count];
		}
	}
	for (int count =0; count < typesOfSalsa;count++)
	{
		if (lowest ==numOfJarsSold[count])
		{
			cout<<" The lowest selling product is: "<<salsa[count]<<endl;	
		}
	}

I added two new loops to display the name of the lowest and highest selling products. does this look right? (it worked)

highest = 0;
	for (int count =0; count < typesOfSalsa ;count++)
	{
		if (numOfJarsSold[count]> highest)
		{	
			highest = numOfJarsSold[count];	
		}
		
	}
	for (int count =0; count < typesOfSalsa;count++)
	{
		if (highest ==numOfJarsSold[count])
		{
			cout<<" The highest selling product is: "<<salsa[count]<<endl;	
		}
	}

	lowest = 999//some number you will never exceed with an input
	for (int count =0; count < typesOfSalsa;count++)
	{
		if (numOfJarsSold[count] <lowest)
		{	
			lowest = numOfJarsSold[count];
		}
	}
	for (int count =0; count < typesOfSalsa;count++)
	{
		if (lowest ==numOfJarsSold[count])
		{
			cout<<" The lowest selling product is: "<<salsa[count]<<endl;	
		}
	}

I'm not sure what numOfJarsSold[0] is so it could possibly make false positives for certain cases, you can combine the two loops that display the lowest and highest ammount, but it isn't necessary, the code looks a-ok aside from the problem I mentioned earlier.

okay thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.