help with my program please!

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;
}





highest = months[0];
for(count = 1; count < rainfall; count++)
{
if(months[count] > highest)
highest = months[count];
}



lowest = months[0];
for (count = 1; count < rainfall; count++)
{
if(months[count] < lowest)
lowest = months[count];
}

highest = months[0];
int temp=0;
for(count = 1; count < rainfall; count++)
{
if(months[count] > highest)
{
highest = months[count];
temp=count;// temp+1 = month which has a highest rainfall
}
}
Last edited on
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.
Topic archived. No new replies allowed.