Arrays and Functions

Hello all, I am having trouble getting my output to come out correctly in this program. Please give suggestions where I messed this thing up.
#include <iostream>
#include <iomanip>
using namespace std;

const int NO_MONS = 12; // number of months

// getData() reads the user data and stores in ary of size elements
// function validates that values entered are 0 or greater
void getData(double ary[], int size);
// calcTot() calculates and returns sum of the values in the ary parameter
// size parameter indicates the number of elements in the array
double calcTot(double ary[], int size);
// calcAvg() calculates and returns the average of the values in the ary parameter
// size parameter indicates the number of elements in the array
double calcAvg(double ary[], int size);
// largest() returns the smallest value in the ary parameter
// size parameter indicates the number of elements in the array
int largest(double ary[], int size);
// smallest() returns the index of the smallest value in the ary parameter
// size parameter indicates the number of elements in the array
int smallest(double ary[], int size);

int main()
{
double rainFall[NO_MONS]; // monthly rainfall data array

getData(rainFall, NO_MONS); // get monthly rainfall data
cout << fixed << showpoint << setprecision(2) << endl; // output formatting
cout << "Total rainfall for the year: ";
cout << calcTot(rainFall, NO_MONS) << " inches\n";
cout << "Average monthly rainfall for the year: ";
cout << calcAvg(rainFall, NO_MONS) << " inches\n";

cout << "Largest amount of rainfall: ";
cout << rainFall[largest(rainFall, NO_MONS)] << " inches in month #";
cout << (largest(rainFall, NO_MONS) + 1) << endl;
cout << "Smallest amount of rainfall: ";
cout << rainFall[smallest(rainFall, NO_MONS)] << " inches in month #";
cout << (smallest(rainFall, NO_MONS) + 1) << endl;

return 0;
}


//Function definitions
void getData(double ary[], int size)
{
double rain;
for(int count = 0; count < NO_MONS; count ++)
{
cout << "Please enter amount of rain fall for the months of the year: ";
cin >> rain;
}
}


double calcTot(double ary[], int size)
{
double total = 0;

for( int count = 0; count < NO_MONS; count++)
{
total += ary[count];

}
return total;
}

int smallest(double ary[], int size)
{
double lowest;

lowest = ary[0];

for(int count = 1; count < NO_MONS; count ++)
{
if (ary[count] < lowest)
lowest = ary[count];
}

return lowest;
}

double calcAvg(double ary[], int size)
{
double total = 0;
double average;

for(int count = 0; count < NO_MONS; count ++)
{
total += ary[count];
average = total / NO_MONS;
}

return average;
}


int largest(double ary[], int size)
{
double highest;
highest = ary[0];

for(int count = 1; count < NO_MONS; count++)
{
if (ary[count] > highest)
highest = ary[count];
}

return highest;
}
Topic archived. No new replies allowed.