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
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
double sumArray( const double [], int );
double getHighest( const double [], int );
int main()
{
const int SIZE = 5;
string name[SIZE] = {"mild", "medium","sweet", "hot", "zesty"};
double sales[SIZE], total, highest, lowest;
cout<<"Enter the salsa sales: "<<endl;
for (int i = 0; i < SIZE; i++)
{
cout<<"Enter the amounts of "<<name[i]<<" sold: ";
cin>>sales[i];
}
highest = getHighest(sales, SIZE);
total = sumArray(sales, SIZE);
cout<<"The total"<<total<<endl;
cout<<name[highest];
return 0;
}
double sumArray(const double array[], int size)
{
double total = 0;
for(int count = 0; count < size; count++)
total +=array[count];
return total;
}
/* double getHighest(double array[], int size)
{
int high = 0;
for (int i = 1; i < size; i++)
{
if (array[i] > array[high])
high = i;
}
return high;
} */
double getHighest(const double array[], int size)
{
double highest = array[0];
for (int count = 1; count < size; count++)
{if(array[count]>highest)
highest= array[count];
}
return highest;
}
|