Rainfall Statistics using arrays and functions

OK, I need help with getting my program to return the actual month instead of the value for the highest/lowest values. I have my program written to find the high/low numerical value but I'm at a loss for the month. I think i'm missing a part in the int main() function. Any help is appreciated!! Here's my code :

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// Function prototypes
double getTotal(double [], int);
double getAverage(double[], int);
double getLowest(double[], int);
double getHighest(double[], int);

int main()
{
const int SIZE = 12;
string months[] = { "January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December" };
double rainfall[SIZE];
double total, highest, lowest;
float average;

// Input the monthly rainfall amount
cout << "Enter the montly rainfall amount for each\n"
<< "month of the year.\n";
for (int count = 0; count < SIZE; count++)
{
cout << months[count] << " : ";
cin >> rainfall[count];
while (rainfall[count] < 0)
{
cout << "Please enter a postive number for the rainfall amount.\n";
cout << months[count] << " : ";
cin >> rainfall[count];
}
}


// Get the total rainfall for the year
total = getTotal(rainfall, SIZE);

// Get the average monthly rainfall
average = getAverage(rainfall, SIZE);

// Get the lowest value rainfall for the year
lowest = getLowest(rainfall, SIZE);


// Get the highest value rainfall for the year
highest = getHighest(rainfall, SIZE);

cout << "\n---Rainfall Statistics---\n\n";
cout << "Total Rainfall: " << setw(6)
<< total << endl;
cout << "Lowest Rainfall: " << setw(6)
<< lowest << endl;
cout << "Highest Rainfall: " << setw(6)
<< highest << endl;
cout << "Average Rainfall: " << setw(6)
<< fixed << showpoint << setprecision(1)
<< average << endl;

}

//*************************************************
// getTotal function adds all the entries for *
// rainfall, and returns the total *
//*************************************************

double getTotal(double rainfall[], int size)
{
double total = 0; // accumulator

// Add each months entry to the total
for (int count = 0; count < size; count++)
total += rainfall[count];

// Return the total
return total;
}

//************************************************
// getAverage function adds the entries for the *
// rainfall, then divides by the number of months*
// and returns the average value *
//************************************************

double getAverage(double rainfall[], int size)
{
double total = 0; // accumulator
double average; // hold average
for (int count = 0; count < size; count++)
total += rainfall[count];
average = total / size;

// return the average
return average;
}

//***********************************************
// getLowest function uses a for statement to *
// find the smallest value entered by user *
// and returns lowest *
//***********************************************

double getLowest(double rainfall[], int size)
{
double lowest; // hold lowest value
string lowMonth; // hold low month

// Get the array's first entry
lowest = rainfall[0];

// Compare the first entry to the rest
// of the array's entry and find the
// lowest element entered
for (int count = 1; count <= size; count++)
{
if (rainfall[count] < lowest)
lowest = rainfall[count];
}
// return the lowest value
return lowest;
}

//***********************************************
// getHighest function uses a for statement to *
// find the highest value entered by user *
// and returns highest *
//***********************************************

double getHighest(double rainfall[], int size)
{
double highest; // hold highest value

// Get the array's first entry
highest = rainfall[0];

// Compare the first entry to the rest
// of the array's entries and find the
// highest element entered
for (int count = 1; count < size; count++)
{
if (rainfall[count] > highest)
highest = rainfall[count];
}
// return highest
return highest;
}
Topic archived. No new replies allowed.