Question
C++ Chips and Salsa Write a program that lets a maker of chips and salsa keep track of sales for five different types of salsa:
C++ Chips and Salsa Write a program that lets a maker of chips and salsa keep track of sales for five different types of salsa: mild, medium, sweet, hot, and zesty. The program should use two parallel 5-element arrays: an array of strings that holds the five 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. Input Validation: Do not accept negative values for number of jars sold.
** QUESTION: I'm having trouble with an issue which this code, if i input the numbers for example 25,25,25,13,13 How do I display 3 high seller (mild, medium, sweet) and 2 low sellers (hot, zesty)? In my code it will only show one. Please Help. Thank you
Here is my code.
#include
//Function prototypes int getSalesData(string[], int[]); int posOfLargest(int[]); int posOfSmallest(int[]); void displayReport(string[], int[], int);
const int SIZE = 5;
int main() { string name[SIZE] = { "mild ", "medium", "sweet ", "hot ", "zesty " }; int sales[SIZE]; //holds jars sold for each salsa type
int totalJarsSold = getSalesData(name, sales);
displayReport(name, sales, totalJarsSold); system("pause");
return 0;
}
/************************************************************ * getSalesData * * Accepts the sales figures for each slasa type and stores * * them in the array passed to the functions, as well as * * accutmulating and returning the totla * ************************************************************/
int getSalesData(string name[], int sales[]) { int total = 0;
for (int type = 0; type < SIZE; type++) { cout << "Jars sold last month of " << name[type] << ": "; cin >> sales[type];
while (sales[type] < 0) { cout << "Jars sold last must be 0 or more. Please re-enter: "; cin >> sales[type]; } total += sales[type]; } return total;
}
/******************************************************** * displayReport * * Displays the sales reprot using information from the * * arrays passed to it. * ********************************************************/ void displayReport( string name[], int sales[], int total) { int hiSalesProduct = posOfLargest(sales); int loSalesProduct = posOfSmallest(sales);
cout << " Salsa Sales Report "; cout << "name Jars Sold "; cout << "______________________ ";
for (int type = 0; type < SIZE; type++) cout << name[type] << setw(11) << sales[type] << endl;
cout << " Total Sales: " << total << endl; cout << "Hight Seller: " << name[hiSalesProduct] << endl; cout << "Low Seller: " << name[loSalesProduct] << endl; }
/************************************************************* * posOfLargest * * Finds the returns the subscript of the array position * * holding the largest value in the array passed to the * * Functions. * **************************************************************/ int posOfLargest(int array[]) { int indexOfLargest = 0;
for (int pos = 1; pos < SIZE; pos++) { if (array[pos]> array[indexOfLargest]) indexOfLargest = pos; } return indexOfLargest; }
/************************************************************ * posOfSmallest * * Finds and returns the subscript of the array position * * holding the smallest value in the array passed to the * * function * *************************************************************/ int posOfSmallest(int array[]) { int indexofSmallest = 0;
for (int pos = 1; pos < SIZE; pos++) { if (array[pos] < array[indexofSmallest]) indexofSmallest = pos; } return indexofSmallest; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started