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

Find 6 errors in this code. // This program uses two arrays to record the names

ID: 3770969 • Letter: F

Question

Find 6 errors in this code.

// This program uses two arrays to record the names of 6 types of pizza
// and the sales numbers for each of these types
// The program then finds the best and the worst selling pizzas

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

int main()
{
const int ARR_SIZE=6;
int name[ARR_SIZE]=["Pepperoni","Prociutta","Vegetarian",
"Sausage","Supreme","Mozarella"];
int sales[ARR_SIZE];
int worstseller_number, bestseller_number;
string worstseller_name, bestseller_name;

for(int i=1; i<ARR_SIZE; i++)
{
cout << "Enter sales for " << name[i] << ": ";
cin >> sales[i];
}

worstseller_name = bestseller_name = name[0];
worstseller_number = bestseller_number = sales[0];

for(int i=0; i<=ARR_SIZE; i++)
{
if(sales[i]<worstseller_number)
{
worstseller_number=i;
worstseller_name=name[i];
}
if(sales[i]<bestseller_number)
{
bestseller_number=sales[i];
bestseller_name=name[i];
}
}

cout << "The bestselling pizza is " << bestseller_name << " with the sales of "
<< bestseller_number << endl;
cout << "The worst selling pizza is " << worstseller_name << " with the sales of "
<< worstseller_number << endl; }

Explanation / Answer

1. Every C and C++ programs contains header files. Those header files are called by #include statement.

2. In the given program also program starts with header files. But here there is a error in first line. The format to call a header files in C and C++ is #include<studio.h> or #include"studio.h". There is an error in first line.

3. Similarly there is an error in second line.

4. The main method of the program shows it returns an integer type. But in the program it does not return any value. Therefore it has an error it returns some value.

5. Initialization of name[ARR_SIZE] shows an error. Because the correct statement isname[ARR_SIZE]={"Pepperoni","Prociutta","Vegetarian",
"Sausage","Supreme","Mozarella"};

Therefore it contains curly braces.

6. Initialization of i is in for loop. It indicates the usage of the variable 'i' is with in a loop. If we use outside of the for loop it shows an error.

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