Arrays and functions

I have a similar problem as GIZMO928 did in FEB 2015

The problem is:
Write a program that lets the user enter the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
Input Validation: Do not accept negative numbers for monthly rainfall figures.

The difference is I must break the code up into four functions:


double getTotal(double [ ], int);
double getAverage(double [ ], int);
double getLowest(double [ ], int, int&); //returns the lowest value, provides the index of the lowest value in the last parameter.
double getHighest(double [ ], int, int&); //returns the highest value, provides the index of the highest value in the last parameter.
When I write the program in one continuous main() function it works.
Then I try to break it up into functions and I get lost. This is what I have so far.

#include "stdafx.h"

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

const int MONTHS = 12;
string name[MONTHS] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
int count = 0;
double rain[MONTHS];
double avg;
double year = 0;
double highest;
string highMonth;
double lowest;
string lowMonth;

double getTotal(double[], int);
double getAverage(double[], int);
double getLowest(double[], int, int&);
double getHighest(double[], int, int&);




void main()



{
int count = 0;

for (count = 0; count < MONTHS; count++)
{
cout << "How many inches of rain does " << name[count];
cout << " have? \n";
cin >> rain[count];
while (rain[count] < 0)
{
cout << "Please enter a number greater than 0." << endl;
cin >> rain[count];
}
}


for (int count = 0; count < MONTHS; count++)
{
cout << name[count];
cout << " has ";
cout << rain[count] << " inches of rainfall.\n";
}
getTotal(rain[months], int);


{
cout << endl;

cout << setprecision(2) << fixed;

cout << "Total Rainfall throughout the year is " << year << " inches" << endl;

cout << "The average monthly rainfall is " << avg << " inches" << endl;

cout << "The month with the highest amount of rainfall is " << highMonth << " with " << highest << " inches." << endl;

cout << "The month with the lowest amount of rainfall is " << lowMonth << " with " << lowest << " inches." << endl;
}
}

double getTotal()
{
for (int count = 0; count < MONTHS; count++)
year += rain[count];

return year;
}

double getAverage()
{
getTotal();
avg = year / MONTHS;

return avg;
}

double getHighest()
{
int count = 0;

highest = rain[0];

for (count = 1; count < MONTHS; count++)
{
if (rain[count] > highest)
{
highMonth = name[count];
highest = rain[count];
}
}
return highMonth, highest;
}

double getLowest()
{
int count = 0;

lowest = rain[0];

for (count = 1; count < MONTHS; count++)
{
if (rain[count] < lowest)
{
lowMonth = name[count];
lowest = rain[count];
}
}
return lowMonth, lowest;
}
Please help. I know it's a mess at this point bu I'm lost.
Topic archived. No new replies allowed.