Rain fall statistics problem

Hello all, I am doing a rainfall statistics problem, My issue is I am not sure how to link the array rain[]; to the other functions. rain[] is the input of rain in numbers for months from 1-12.

Here is the problem and my code, thanks all.


Write a program that lets the user enter the total rainfall in inches 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.
Your program should include 5 functions:
- inputData takes the array and its size. The function should ask the user to fill the array in a clear
way.
- total: takes the array and its size. The function should return the total rainfall for the year.
- average: takes the array and its size. The function should return the average monthly rainfall.
- highest: takes the array and its size. The function should return the month that has the highest
rainfall amount.
- lowest: takes the array and its size. The function should return the month that has the lowest
rainfall amount.
Input Validation: Do not accept negative numbers for monthly rainfall amounts.








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 #include <iostream>
#include <algorithm>
#include <string>

using namespace std;

const int months = 12;
string monthname[months]= { "Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };







void inputArray() {

	double rain[months];

	for (int i = 0; i < months; i++)
	{
		cout << "How many inches of rain does " << monthname[i] << " have? \n";
		cin >> rain[i];
		while (rain[i] < 0)
		{
			cout << "Please enter a number greater than 0." << endl;
			cin >> rain[i];
		}
	}
}
float RainMax(float maxi) {
	string highmonth;

	for (int i = 1; i < months; ++i)
	{
		if (rain[i] > maxi)
		{
			highmonth = monthname[i];
			maxi = rain[i];

		}

		
	}
	return maxi;
}
float RainMin(float mini) {
	string lowmonth;


	for (int i = 1; i < months; ++i)
	{
		if (rain[i] < mini)
		{
			lowmonth = monthname[i];
			mini = rain[i];

		}

		return mini;
	}
}

float Average(float output) {
	double total = 0;
		double  avg = total / months * (1.0);

	for (int i = 0;  i < months; i++)
	{
		total += rain[i];
		cout << monthname[i] << "has " << rain[i] << " inches of rainfall.\n";
	}
	return output;
	cout << "The Average is: <<" << avg << " ";

}

float TotRain(float total) {
	double total = 0;

	for (int i = 0; i < months; i++)
	{
		total += rain[i];
		cout << monthname[i] << "has " << rain[i] << " inches of rainfall.\n";
	}
	
	cout << "The Average is: <<" << total << " ";
	return total;
}


float Average(float);
float RainMin(float);
float RainMax(float);
void inputArray();

int main() {

	void inputArray();

}
Any arrays you create in your functions are only visible and usable in those functions. You should create your array(s) in main and then pass to your functions as one of the function parameters. The other parameter is the size of the passed array.

void inputArray(double rain[], int months)
Can you elaborate on pass to function as parameters?
I reworked on my problem, but I now get errors which quite frankly I do not understand.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

const int months = 12;
string monthname[months] = { "Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };







void inputArray(float rain[]) {

	 rain[months];

	for (int i = 0; i < months; i++)
	{
		cout << "How many inches of rain does " << monthname[i] << " have? \n";
		cin >> rain[i];
		while (rain[i] < 0)
		{
			cout << "Please enter a number greater than 0." << endl;
			cin >> rain[i];
		}
	}
}
float RainMax(float maxi, float rain[]) {
	string highmonth;

	for (int i = 1; i < months; ++i)
	{
		if (rain[i] > maxi)
		{
			highmonth = monthname[i];
			maxi = rain[i];

		}


	}
	return maxi;
}
float RainMin(float mini, float rain[]) {

	string lowmonth;


	for (int i = 1; i < months; ++i)
	{
		if (rain[i] < mini)
		{
			lowmonth = monthname[i];
			mini = rain[i];

		}

		return mini;
	}
}

float Average(float output, float rain[]) {
	double total = 0;
	double  avg = total / months * (1.0);
	output = avg;
	for (int i = 0; i < months; i++)
	{
		total += rain[i];
		cout << monthname[i] << "has " << rain[i] << " inches of rainfall.\n";
	}
	cout << "The Average is: <<" << output << " ";
	return output;
}

float TotRain(float total, float rain[]) {
	 total = 0;

	for (int i = 0; i < months; i++)
	{
		total += rain[i];
		cout << monthname[i] << "has " << rain[i] << " inches of rainfall.\n";
	}

	cout << "The Average is: <<" << total << " ";
	return total;
}


float Average(float, float rain[]);
float RainMin(float mini, float rain[]);
float RainMax(float maxi, float rain[] );
void inputArray(float rain[]);


You try to do too many things at once.
I would start simple.
Just create the function InputArray, compile and test it by printing its values.
Also you should follow the instructions.
into an array of doubles.
- inputData takes the array and its size
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const int months = 12;
string monthname[months] = 
{ 
    "Jan", "Feb", "March", "April", "May", "June", 
    "July", "Aug", "Sept", "Oct", "Nov", "Dec" 
};

void inputArray(double rain[], int size) 
{
	for (int i = 0; i <size; i++)
	{
		cout << "How many inches of rain does " << monthname[i] << " have? \n";
		cin >> rain[i];
	}
}

int main()
{
   double rain_data[months] = {0.0};

  inputArray(rain_data, months);
  // TODO: print the data to see if it works.
}
Topic archived. No new replies allowed.