I fixed the function call, now the only problem is that it won't display the month with the largest/smallest data. Here's what it shows, along with the code following.
Enter the rainfall (in inches) for month #1: 2.5
Enter the rainfall (in inches) for month #2: 10.7
Enter the rainfall (in inches) for month #3: 32
Enter the rainfall (in inches) for month #4: 231
Enter the rainfall (in inches) for month #5: 7.8
Enter the rainfall (in inches) for month #6: 5.4
Enter the rainfall (in inches) for month #7: 2.5
Enter the rainfall (in inches) for month #8: 4.87
Enter the rainfall (in inches) for month #9: 5.8
Enter the rainfall (in inches) for month #10: 20.0
Enter the rainfall (in inches) for month #11: 2.6
Enter the rainfall (in inches) for month #12: 3.8
Total rainfall for the year was 328.97 inches.
Average rainfall for the year was 86.57 inches.
The largest amount of rainfall was 231.00 inches in month 13.
The smallest amount of rainfall was 2.50 inches in month 13.
Press any key to continue
#include<iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double getTotal(double [], int);
double getAverage(double [], int);
double getLargest(double [], int, int &);
double getSmallest(double [], int, int &);
int main()
{
const int NUM_MONTHS = 12;
double rainFall[NUM_MONTHS]; // Stores total rainfall for each month
// Input rainfall amounts and store them in the 12 array locations
for (int month = 0; month < NUM_MONTHS; month++)
{
cout << "Enter the rainfall (in inches) for month #";
cout << (month + 1) << ": ";
cin >> rainFall[month];
while (rainFall[month] < 0)
{ cout << "Rainfall must be 0 or more. Please re-enter: ";
cin >> rainFall[month];
}
}
// Display the total rainfall
cout << fixed << showpoint << setprecision(2) << endl;
cout << "Total rainfall for the year was ";
cout << setw(5) << getTotal(rainFall, NUM_MONTHS) << " inches." << endl;
// Display the average rainfall
cout << "Average rainfall for the year was ";
cout << setw(5) << getAverage(rainFall, NUM_MONTHS) << " inches." << endl << endl;
// Display the months with the largest & smallest amounts of rain.
// The variable index is passed by reference to the getLargest &
// getSmallest functions, so they can assign it the subscript of the
// array element having the largest, or smallest, amount of rainfall.
int index;
cout << "The largest amount of rainfall was " << setw(5);
cout << getLargest(rainFall, NUM_MONTHS, index) << " inches in month ";
cout << (index + 1) << "." << endl;
cout << "The smallest amount of rainfall was " << setw(5);
cout << getSmallest(rainFall, NUM_MONTHS, index) << " inches in month ";
cout << (index + 1) << "." << endl;
return 0;
}
double getTotal(double array[], int size)
{
double total = 0;
for(int count = 0; count < size; count++)
{
total += array[count];
}
return total;
}
double getAverage(double array[], int size)
{
double total;
double average;
for(int count = 0; count < size; count++)
{
total += array[count];
}
for (count = 0; count < size; count++)
{
average = getTotal(array, size) / array[count];
}
return average;
}
double getLargest(double array[], int size, int &count)
{
double largest = array[0];
for (count = 1; count < size; count++)
{ if (array[count] > largest)
largest = array[count];
}
return largest;
}
double getSmallest(double array[], int size, int &count)
{
double smallest = array[0];
for (count = 1; count < size; count++)
{ if (array[count] < smallest)
smallest = array[count];
}
return smallest;
}