Ok this program takes rainfall data for every month of the year and displays the total and avg for each month. I need it to display each month in order of rainfall from highest to lowest as well.
Im having a hard time implementing showorder into my code. Can someone give me a hand? Thank you very much
#include <iostream.h>
#define MAXSIZE ]2
void fillArray(float [MAXSIZE]);
void checkArray(float [MAXSIZE]);
int main(void)
{
float rain[MAXSIZE];
fillArray(rain);
checkArray(rain);
return 0;
}
void fillArray(float r[MAXSIZE])
{
int i;
for(i = 0; i < MAXSIZE; i++)
{
cout << "Enter rainfall for month " << i + 1 << " : ";
cin >> r[i];
if(r[i] < 0)
{
cout << "Rainfall cannot be negatige -- try again." << endl;
i--;
}
}
}
void checkArray(float a[MAXSIZE])
{
float max, min, tot, avg;
int i, maxmonth, minmonth;
max = min = a[0];
tot = avg = 0.0;
maxmonth = minmonth = 1;
for(i = 0; i < MAXSIZE; i++)
{
if(max < a[i])
{
max = a[i];
maxmonth = i + 1;
}
if(min > a[i])
{
min = a[i];
minmonth = i + 1;
}
tot = tot + a[i];
avg = tot / (i + 1);
}
cout.precision(2);
cout.setf(ios::showpoint | ios::fixed);
cout << "The largest rainfall was " << max << " in month " << maxmonth << "." << endl;
cout << "The smallest rainfall was " << min << " in month " << minmonth << "." << endl;
cout << "The total rainfall was " << tot << "." << endl;
cout << "The average rainfall was " << avg << "." << endl;
}