Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Here are the corrected errors in the code:

#include <iostream>

#include <string>

using namespace std;

int main()

const int ARR_SIZE = 6; // Declare the array size and set it to 6

// Declare the array of pizza names and record values in it

string name[ARR_SIZE] = {"Pepperoni", "Prosciutto", "Vegetarian", "Sausage",


"Supreme", "Mozzarella"};

int sales[ARR_SIZE]; // Declare the sales array

int worstseller_number, bestseller_number; // The subscripts of the best- and


worstseller

string worstseller_name, bestseller_name; // The names of the best- and


worstseller

for (int i = 0; i < ARR_SIZE; i++) // Loop to enter all sales numbers

cout << "Enter sales for " << name[i] << ": ";

cin >> sales[i];

// Initialize bestseller and worstseller data with the first pizza

worstseller_name = bestseller_name = name[0];

worstseller_number = bestseller_number = sales[0];

for (int i = 1; i < ARR_SIZE; i++) // Loop through all elements in sales[]
{

if (sales[i] < worstseller_number) // If an element is less than the lowest...

worstseller_number = sales[i]; // make the lowest sales equal to its sales

worstseller_name = name[i]; // make the worstseller name equal to its


name

if (sales[i] > bestseller_number) // If an element is higher than the highest...

bestseller_number = sales[i]; // make the highest sales equal to its sales

bestseller_name = name[i]; // make the bestseller name equal to its


name

cout << "The bestselling pizza is " << bestseller_name << " with the sales of "

<< bestseller_number << endl; // Display the best selling pizza

cout << "The worst selling pizza is " << worstseller_name << " with the sales of
"

<< worstseller_number << endl; // Display the worst selling pizza

return 0;

Corrections made:

1. Changed the array size declaration to const int ARR_SIZE = 6;.


2. Added #include <string> for using string data type.
3. Added a space between using and namespace (using namespace std;).
4. Changed the loop index to start from 0 (for (int i = 0; i < ARR_SIZE; i++)).
5. Corrected the comparison in the bestseller loop to use > instead of <.
6. Fixed comments to accurately describe the actions in the code.

You might also like