Skip to content

Instantly share code, notes, and snippets.

@zachlatta
Created April 17, 2012 04:35
Show Gist options
  • Save zachlatta/2403475 to your computer and use it in GitHub Desktop.
Save zachlatta/2403475 to your computer and use it in GitHub Desktop.
/* Write a program that lets a maker of chips and salsa keep track of their sales
for five different types of salsa they produce: mild, medium, sweet, hot, and
zesty. It should use two parallel five-element arrays: an array of strings that
holds the five salsa names and an array of integers that holds the number of jars
sold during the past month for each salsa type. The salsa names should be stored
using an initialization list at the time the name array is created. The program
should prompt the user to enter the number of jars sold for each type. Once this
sales data has been entered, the program should produce a report that displays
sales for each salsa type, total sales, and the names of the highest selling and
lowest selling products.
Input validation: Do not accept negative values for number of jars sold.*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(int argc, char const *argv[])
{
int index, high = 0, low = 0;
string salsa[5] = {"mild", "medium", "sweet", "hot", "zesty"};
int jars[5];
for (index = 0; index!=5; index++)
{
cout << "Please enter the number of jars of " << salsa[index] << " salsa sold in the past month: ";
cin >> jars[index];
}
cout << "================================================================================" << endl;
cout << "=====================================REPORT=====================================" << endl;
cout << "================================================================================" << endl;
cout << endl;
cout << left << setw(40) << "Salsa" << right << setw(40) << "# sold" << endl;
for (index = 0; index!=5; index++)
{
cout << left << setw(40) << salsa[index] << right << setw(40) << jars[index] << endl;
}
cout << endl << left << setw(40) << "Total # sold:" << right << setw(40) << jars[0]+jars[1]+jars[2]+jars[3]+jars[4] << endl;
for(index = 0; index < 5; index++)
{
if(jars[index]>high)
high=jars[index];
}
cout << left << setw(40) << "Highest selling product:" << right << setw(40) << salsa[index] << endl;
for(index = 0; index < 5; index++)
{
if(jars[index]<low)
low=jars[index];
}
cout << left << setw(40) << "Lowest selling product:" << right << setw(40) << salsa[index] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment