1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <iostream>
#include <string>
using namespace std;
//func prototype***********************************************************
void maxMinFunc(string [], int [], int);
void total(int [], int);
void displaySales(string [], int [], int);
//*************************************************************************
int main()
{
const int size = 5;
string names[] = {"Mild", "Medium", "Sweet", "Hot", "Zesty"};
int sales[size];
//asks user for sales for each type of salsa
for (int index = 0; index < size; index++)
{
cout << "What are the sales for " << names[index] << "?" << endl;
cin >> sales[index];
}
cout << endl;
displaySales(names, sales, size); //displays name and sales for each type
cout << endl;
total(sales, size); //calculates & displays total amount of sales
cout << endl;
maxMinFunc(names, sales, size); //calculates & displays min and max salsa sold
return 0;
}
//func header***************************************************************
void maxMinFunc(string names[], int sales[], int size)
{
int max = sales[0];
int min = sales[0];
string minName = names[0];
string maxName = names[0];
for (int index = 0; index < size; index++)
{
if (sales[index] < min)
{
min = sales[index];
minName = names[index];
}
if (sales[index] > max)
{
max = sales[index];
maxName = names[index];
}
}
cout << maxName << " has sold the most at " << max << " sales." << endl;
cout << minName << " has sold the most at " << min << " sales." << endl;
}
void total(int sales[], int size)
{
int total = 0;
for (int index = 0; index < size; index++)
{
total += sales[index];
}
cout << "The total amount of jars sold is " << total << "." << endl;
}
void displaySales(string names[], int sales[], int size)
{
for (int index = 0; index < size; index++)
{
cout << "The sales for " << names[index] << " is " << sales[index]
<< " jars." << endl;
}
}
//**************************************************************************
|