Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chips and Salsa C++ help. Ch 7 of C++ from Control structures throyugh Objects.

ID: 3818528 • Letter: C

Question

Chips and Salsa C++ help.

Ch 7 of C++ from Control structures throyugh Objects.

Produce a table that displays the sales for each type of salsa, the total sales, and the names of the highest selling and lowest selling products.

I can do the first two, but how do I make the program output the names of the highest and lowest selling product instead of the numbers.

Here is my code

// Assignment 7

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
       const int type = 5;
       const int string = 7;
       char salsa[type][string] = { "mild", "medium", "sweet", "hot", "zesty" };
       int num[type];
       int total = 0;
       int highest;
       int lowest;
       for (int count = 0; count < type; count++)
       {
           cout << "Enter the number of " << salsa[count] << " salsa jars sold: ";
           cin >> num[count];
           while (num[count]<0)
           {
               cout << "Enter a positive number: ";
               cin >> num[count];
           }

           total += num[count];
       }

       // Display the table headings.
       cout << " Salsa Sold ";
       cout << " ";
       cout << "---------------------------------- ";
       for (int count = 0; count < type; count++)
       {
           cout << salsa[count] << " " << num[count] << endl;
       }
       cout << "Total: " << " " << total << endl;

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

           }

       }
       cout << "The lowest selling product is: " << lowest << endl;
       system("pause");
   }

Here is the full question if that helps

Create a string array that stores five different types of salsas: mild, medium, sweet, hot, and zesty. The salsa names should be stored using an initialization list at the time the name array is created. Have the program prompt the user to enter the number of salsa jars sold for each type of salsa using an array. Do not accept negative values for the number of jars sold. Produce a table that displays the sales for each type of salsa, the total sales, and the names of the highest selling and lowest selling products

Explanation / Answer

It is possible to print highest selling product and lowest selling product names.

Store the "count" value while calculating highest and lowest selling numbers.For example the following code can be modified as:

for (int count = 0; count < type; count++)
       {
           if (num[count]> highest)
           {
               highest = num[count];
           }
       }

Modified Code:

for (int count = 0; count < type; count++)
       {
           if (num[count]> highest)
           {
               highest = num[count];
                highest_count = count;
           }
       }

This highest_count will help you to print highest selling product name and similar thing can be done for lowest selling product name.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote