the program should have a getData function that accepts the total rainfall for each of the 12 months from the user, and stores it in a double array. It should also have four value-returning functions that compute and return to main the totalRainfall, averageRainfall, driestMonth, and wettestMonth. The last two functions will return the number of the month with the lowest and highest rainfall amounts, not the amount of rain that fell in those months.

#include<iostream>
#include<iomanip>
#include <stdlib.h>
using namespace std;
double getTotal(double[], int);
double getHighest(double [], double);
double getLowest(double [], double);
double getAverage(double[], double);



int main () {
const int MONTHS = 12;
int months[MONTHS]= {"01", "02", "03", "04",
"05", "06", "07", "08",
"09", "10", "12"};
double rainfall[MONTHS];


for (int index = 0; index < MONTHS; index++)
{
cout << "Enter the rainfall (in inches for the months) ";
cout  << months [index + 1]<<":";
//cin >> rainfall[index];
}
cout << "***Sumary" << endl;
cout << "Total rainfall: " << getTotal(rainfall ,12) << "inches"<< endl;
//count << "Average monthly rainfall: " << getAverage(rainfall , 12) <<endl;



system("pause");
return 0;
}


double getTotal(double rF[], int MONTHS)
{
double total = 0;
for (int index =0; index < MONTHS; index++)
total+=rF[index];
return total;
}


double getAverage (double rF[], double size)
{
double average = 0.0;
double total = 0;
double rainfall;
for(int index = 0; index < size; index++)
total += rF [index];
average =total / rainfall;
return average;
}


double getHighest(double rF[], double size)
{
double highest;
highest = rF[0];
for ( int index =1; index < size; index++)
{
if(rF[index] > highest)
highest = rF[index];
return highest;
}
}


double getLowest(double rF[], double size)
{
double lowest;
lowest = rF[0];
for (int index = 0; index < size; index++)
{
if(rF[index] < lowest )
lowest = rF[index];
return lowest;
}
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

Sigh. Why, oh why, do people not read the very-clearly-marked "Read This Before Posting A Question" sticky-thread at the top of the Forum?

Hi alexander1s, welcome to DaniWeb, and sorry to be such a grump, but this is probably the fifth post I've read in the past 15 minutes that doesn't follow the most basic instructions! The most commonly-violated directives are:

1) Don't post into ancient threads. (you didn't do this, so no worries.)
2) Surround your posted code with [ CODE ] tags. (you didn't do this either, but you should have.)

That said, there's no indication in your posted code as to where your problem is occurring. In fact, it looks like your only reference to cin is currently commented-out. Though I doubt that's what you meant when you say you're getting the wrong data.

Edited 5 Years Ago by raptr_dflo: n/a

When I enter the 12 months it should display the getTotal of the function but its asking me to enter months again instead of displaying the total

This actually compiles?

int months[MONTHS]= {"01", "02", "03", "04",
"05", "06", "07", "08",
"09", "10", "12"};

"01" isn't an integer.

I change to string and the months such as Jun,feb, and so on but when I enter the inches in the months it will repeat asking to enter inches again but without showing the months

What you are describing doesn't match the code you posted. I see at least one problem in addition to the one I mentioned, plus the whole "cin commented out" aspect that raptr_dflo mentioned. Plus you've apparently changed it. You need to post the current code inside code tags.

This article has been dead for over six months. Start a new discussion instead.