Question: Write a C++ program that keeps track of chips and salsa sales for five types of salsa: mild, medium, sweet, hot, and zesty. The program

Write a C++ program that keeps track of chips and salsa sales for five types of salsa: mild, medium, sweet, hot, and zesty.

The program should:

Use two parallel arrays. One for the salsa type and one for number of jars of this type sold this month.

The salsa type array should be initialized using an initialization list at the beginning of the program.

Using 2 loop(s), the program should:

prompt the user to enter number of jars sold per salsa type.

display salsa type and number of jars sold per type on one line.

The program should display the total number of jars of all types sold for the month.

How do i use 2 parallel arrays?

//******************************************************************

#include

#include

#include

using namespace std;

// Function prototypes

int getTotal(int [], int);

int main()

{

const int NUM_TYPES = 5;

int sales[NUM_TYPES];

string name[NUM_TYPES] = {"Mild Sauce", "Medium Sauce", "Sweet Sauce", "Hot Sauce", "Zesty Sauce"};

// Create the arrays for the names and sales amounts

int totalJarsSold,

// Input the number of jars sold

for (int type = 0; type < NUM_TYPES; type++)

{

cout << "Number of " << name[type] << " jars sold: ";

cin >> sales[type];

while (sales[type] < 0)

{ cout << "Number of jars sold must be 0 or more. Please re-enter: ";

cin >> sales[type];

}

}

// Call functions to get total sales and high and low selling products

totalJarsSold = getTotal(sales, NUM_TYPES);

// Produce the sales report

cout << endl << endl;

cout << "Salsa Sales Report ";

cout << "Name Jars Sold ";

cout << name[0] << " " << sales[0] << " ";

cout << name[1] << " " << sales[1] << " ";

cout << name[2] << " " <

cout << name[3] << " " << sales[3] << " ";

cout << name[4] << " " << sales[4] << " ";

// insert the code that prints the salsa names and number jars sold

cout << " Total Sales:" << setw(18) << totalJarsSold << endl;

return 0;

}

/************************************************************

* getTotal *

* Calculates and returns the total of the values stored in *

* the array passed to the function. *

************************************************************/

int getTotal (int array[], int numElts)

{

int total = 0;

for (int type = 0; type < numElts; type++)

total += array[type];

return total;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!