I have to print out which months have the lowest and highest amount of rainfall.
I know how to find the lowest and highest value but how do I match them with there month?
#include <iostream>
using namespace std;
int main()
{
const int rainfall = 12;
double months[rainfall];
int count;
int highest;
int lowest;
cout << "Enter the rainfall for each month" << endl;
for (int index = 0; index < rainfall; index++)
{
cout << "Month #" << (index + 1) << ":";
cin >> months[index];
}
double total = 0;
double average;
for(int count = 0; count < rainfall; count++)
{
total += months[count];
average = total / rainfall;
}
The month corresponds to the array index (+1) - you could keep track of that the way you're keeping track of the highest and lowest. If you update the highest or lowest in the if statement, you could add a statement to update a variable holding the index corresponding to that new highest or lowest rainfall amount.