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";
//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;
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.