I am working on a rainfall program that will ask the user to enter the total rainfall for each month, then will calculate the total rainfall for the year, the average monthly rainfall and is supposed to display the month names for the highest and lowest month. I have everything else working but my months are displaying numbers not the actual month. I have looked at previous rainfall programs in daniweb, but they are of no help, I am a beginner, pls help
#include <iostream>
using namespace std;
int main()
{
const int NUM_MONTHS = 12; //number of values
int values[NUM_MONTHS]; //each value
int month; //loop counter
int lowest, highest, rainfall, count;
double average;
double total = 0;
//Array with the names of the months
string months[NUM_MONTHS] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
//Input rainfall for each month
for(int month = 1; month <= NUM_MONTHS; month++)
{
cout << "Enter the total rainfall for " << months[month-1] << ": ";
cin >> rainfall;
//Input validation - enter a value over or equal to 0
if ( rainfall < 0 )
{
cout << "The number you have entered is invalid." << endl;
cout << "Please reenter: ";
cin >> rainfall;
}
//Calculate total rainfall for the year
total += rainfall;
}
//Calculate the average monthly rainfall
average = total/12;
//Find the months with the highest rainfall and lowest rainfall
highest = values[0];
lowest = values[0];
for(int month = 0; month < NUM_MONTHS; month++)
{
if(values[month] > highest)
highest = values[month];
if(values[month] < lowest)
lowest = values[month];
}
//Display total rainfall for year, monthly average, highest and lowest months
cout << "\n\nThe total rainfall for the year is: " << total << " inches"
<< "\nThe average monthly rainfall is: " << average << " inches";
cout << "\nThe month with the highest rainfall is: " << highest
<< "\nThe month with the lowest rainfall is: " << lowest << endl;
system("pause");
return 0;
}