Out putting info from functions using arrays

I have been working on this program to calculate average rain fall for a homework problem. I am having trouble because when I call my functions I am getting a bunch of gibberish as output. I am not sure what I am doing wrong. can anyone help? I will post my code that I have.



#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;
}
Can anyone tell me what I am doing wrong? I feel like it could be in my function definitions or the way I am calling them? My main was given to me by my professor so I was trying to implement the functions based on that.
Topic archived. No new replies allowed.