I am having a lot of issues trying to solve my errors on my code for Chips and S
ID: 3810879 • Letter: I
Question
I am having a lot of issues trying to solve my errors on my code for Chips and Salsa. Visual Studio says I have 8 errors: Lines 62, 72, 84, 85, 88
#include<iostream>
#include<iomanip>
using namespace std;
// Constant for types of salsa
const int size =5;
// Function Prototypes
int lowestIndex(int[], int);
int highestIndex (int[], int);
int main()
{
// Declare Ints
int Highest;
int Lowest;
// Salsa Names Array
string salsa [size]=
{
"Mild", "Medium", "Hot", "Sweet", "Zesty"
};
// Sales Array
int sales[5];
// Get Amount of Salsa Sold
cout << "Please enter the amount of Mild salsa sold: ";
cin >> sales[0];
cout << "Please enter the amount of Medium salsa sold: ";
cin >> sales[1];
cout << "Please enter the amount of Hot salsa sold: ";
cin >> sales[2];
cout << "Please enter the amount of Sweet salsa sold: ";
cin >> sales[3];
cout << "Please enter the amount of Zesty salsa sold: ";
cin >> sales[4];
if(sales[0] < 0 || sales[1] < 0 || sales[2] < 0 || sales[3] < 0 || sales[4] < 0)
{
cout << "Amount sold must be 0 or more. "
<< "Please re-enter: ";
cin >> sales[0];
}
// Display Results
cout << " ***************************************************";
cout << " Here are the results accoring to your amounts sold ";
cout << "Mild: " << sales[0] << " ";
cout << "Medium: " << sales[1] << " ";
cout << "Hot: " << sales[2] << " ";
cout << "Sweet: " << sales[3] << " ";
cout << "Zesty: " << sales[4] << " ";
cout << " *****************************************************";
// Functions for Highest and Lowest from Index
int highestIndex(int sales[], int size)
{
int x = 0;
for(int i=0; i<size; i++)
{
if (sales[i]> sales[x])
x=i;
}
return x;
}
int lowestIndex(int sales[], int size)
{
int x = 0;
for(int i=0; i<size; i++)
{
if(sales[i] < sales [x])
x=i;
}
return x;
}
// Highest and Lowest Sales
Lowest = lowestIndex(sales, size);
cout << "The salsa type with the lowest sales is: " << salsa[Lowest] << " " << endl;
Highest = highestIndex(sales, size);
cout << "The salsa type with the highest sales is: " << salsa[Highest] << " " << endl;
system("pause");
return 0;
}
Explanation / Answer
// C++ code
#include <iostream>
#include <iomanip>
using namespace std;
// Constant for types of salsa
const int size =5;
// Function Prototypes
int lowestIndex(int[], int);
int highestIndex (int[], int);
int main()
{
// Declare Ints
int Highest;
int Lowest;
// Salsa Names Array
string salsa [] ={"Mild", "Medium", "Hot", "Sweet", "Zesty"};
// Sales Array
int sales[5];
// Get Amount of Salsa Sold
cout << "Please enter the amount of Mild salsa sold: ";
cin >> sales[0];
cout << "Please enter the amount of Medium salsa sold: ";
cin >> sales[1];
cout << "Please enter the amount of Hot salsa sold: ";
cin >> sales[2];
cout << "Please enter the amount of Sweet salsa sold: ";
cin >> sales[3];
cout << "Please enter the amount of Zesty salsa sold: ";
cin >> sales[4];
if(sales[0] < 0 || sales[1] < 0 || sales[2] < 0 || sales[3] < 0 || sales[4] < 0)
{
cout << "Amount sold must be 0 or more. "
<< "Please re-enter: ";
cin >> sales[0];
}
// Display Results
cout << " ***************************************************";
cout << " Here are the results accoring to your amounts sold ";
cout << "Mild: " << sales[0] << " ";
cout << "Medium: " << sales[1] << " ";
cout << "Hot: " << sales[2] << " ";
cout << "Sweet: " << sales[3] << " ";
cout << "Zesty: " << sales[4] << " ";
cout << " *****************************************************";
// Functions for Highest and Lowest from Index
// Highest and Lowest Sales
Lowest = lowestIndex(sales, size);
cout << " The salsa type with the lowest sales is: " << salsa[Lowest] << " " << endl;
Highest = highestIndex(sales, size);
cout << " The salsa type with the highest sales is: " << salsa[Highest] << " " << endl;
//system("pause");
return 0;
}
int highestIndex(int sales[], int size)
{
int x = 0;
for(int i=0; i<size; i++)
{
if (sales[i]> sales[x])
x=i;
}
return x;
}
int lowestIndex(int sales[], int size)
{
int x = 0;
for(int i=0; i<size; i++)
{
if(sales[i] < sales [x])
x=i;
}
return x;
}
/*
output:
Please enter the amount of Mild salsa sold: 56
Please enter the amount of Medium salsa sold: 76
Please enter the amount of Hot salsa sold: 55
Please enter the amount of Sweet salsa sold: 56
Please enter the amount of Zesty salsa sold: 33
***************************************************
Here are the results accoring to your amounts sold
Mild: 56
Medium: 76
Hot: 55
Sweet: 56
Zesty: 33
*****************************************************
The salsa type with the lowest sales is: Zesty
The salsa type with the highest sales is: Medium
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.