array

Pages: 12
Am I doing this right, can I clean it up a bit?

Write a modular program that analyzes a year's worth of rainfall data. In addition to main, 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. These last two functions return the number of month with the lowest and highest rainfall amounts, not the amount of rain that fell those months. Notice that this months number can be used to obtain the amount of rain that fell those months. This information should be used either by main or by a displayReport function called by main to print a summary rainfall report.

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
[output]#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

void tableFormat(string,string,string,string);
void tableFormat(double,double,double,double);

int main () 
{
	double avgRain = 0;
	double rainSum = 0;
	int count = 0;
	double monthlyTotals[12];
	string outRainSum;
	double lowpoint=100000;
	double highpoint=0;
	string lowMonth;
	string highMonth="January";
	string monthNames[] = {"January","Febuary","March","April","May","June","July","August","September","October","November","December"};
	cout << "Please enter the amount of rainfall for each month, and press enter after each" << endl;
	for (count = 0; count <= 11; count++)
	{
		cout<< monthNames[count] << " : ";
		cin >> monthlyTotals[count];
		while (monthlyTotals[count] < 0)
		{
			cout << "Please reenter a positive number for the month of " << monthNames[count] << endl;
			cin >> monthlyTotals[count];
		}
	}
		
	
	for (count =0; count <=11; count++)
		rainSum = rainSum + monthlyTotals[count];
	avgRain = rainSum / 12;
	for (count = 0; count <=11; count++)
	{	cout << endl;
		cout << monthNames[count] << "\t" << monthlyTotals[count] << endl;
	}
	highpoint = monthlyTotals[0];	
	for (count=0; count<=11; count++) 
	{
	if (monthlyTotals[count] >= highpoint)
	{
		highpoint = monthlyTotals[count];
		highMonth = monthNames[count];
	}
	}
	lowpoint = monthlyTotals[0];	
	for (count=0; count<=11; count++) 
	{
		if (monthlyTotals[count] <= lowpoint)
		{
		lowpoint = monthlyTotals[count];
		lowMonth = monthNames[count];
		}
	}
	tableFormat("Total","Average","Lowpoint","Highpoint");
	tableFormat(rainSum, avgRain, lowpoint,highpoint);
	cout << "The month(s) with the lowest rainfall is ";
	for (count=0; count <=11; count++)
	 
		if (monthlyTotals[count] == lowpoint)
			cout << monthNames[count] << ", ";
	
	cout << "with a rainfall of: "<< lowpoint << "." << endl;
	cout << "The month(s) with the highest rainfall is ";
	for (count=0; count <=11; count++)
		
		if (monthlyTotals[count] == highpoint)
			cout << monthNames[count] << ", ";
	
	cout << " with a rainfall of: "<< highpoint <<"." << endl;
	
	return 0;
}

void tableFormat(string colA,string colB,string colC,string colD)
{
	cout <<setw(15) << fixed <<  colA <<setw(15) << fixed <<  colB <<setw(15) << fixed <<  colC <<setw(15) << fixed <<  colD <<endl;
}
void tableFormat(double colA,double colB,double colC,double colD)
{
	cout << setprecision(3)<<setw(15) << fixed <<  colA <<setw(15) << fixed <<  colB <<setw(15) << fixed <<  colC <<setw(15) << fixed <<  colD << endl;
}
[/output]
Looks good overall, though there's a couple things that feel a little redundant. Like, "and press enter after each." The user probably knows this already, but you can leave that there if you want.

The other thing I would change is removing lines 37-40. (Where it outputs the rainfall for each month.) This is already taken care of when the user was asked to input the numbers. So outputting what they just inputted kind of clutters the screen.

You could also start your counters at 1. That way you can do "count<=12", but whatever works for you is fine. :)

If you want to "prettify" you code, you can do the following: (This is how my instructor taught me.)
1
2
3
4
5
6
7
8
9
10
11
12
13
//  ========================================================
    functionType FunctionName( identifierType identifier ) {

//      ======================
//      Variable Declarations.
//      ======================
        int someNum = 1234;
//      ===================

//      Your code and whatnot.

    } // function FunctionName()  You can also do this for: //if, //else, //switch, etc.
//  ============================ 


Hope this helps. ;)

Edit: I've corrected my stupid mistakes. :P
Last edited on
I tried something different with the code. Does this look better, and how can I make it work?

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
#include <iostream>
#include <string>
using namespace std;

//Prototypes
int getData(string name[], int month[]);
int averageRainfall();
int driestMonth(int[]);
int wettestMonth(int[]);
void displayReport (string[],int[],int);

//Array Size
const int size = 12;

int main()
{
	//Array Info
	string name [size] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
	int month [size];

	//Show Info
	cout<<"The 2010 Rain Report for Neversnows County"<<endl;
	cout<<endl;

	int totalRainfall=getData(name,month);
	displayReport(name,month,totalRainfall);
	
	return 0;
}

//Collect Data
int getData(string name[], int month[])
{
	int count=0;
	int total=0;

	cout << "Please enter the amount of rainfall for each month" << endl;
	for (count; count <= 11; count++)
	{
		cout<< name[size] << " : ";
		cin >> month[size];
		while (month[size] < 0)
		{
			cout << "Please re-enter a positive number for the month of " << name[size] << endl;
			cin >> month[size];
		}
	}
	return total;
}

//Show The Data
void displayReport(string name[],int sales[], int total)
{
	int hiSalesProduct=wettestMonth(sales);
	int loSalesProduct=driestMonth(sales);

	cout<<"\nThe total rainfall is: "<<total<<endl;
	cout<<"The wettest month is: "<<name[hiSalesProduct]<<endl;
	cout<<"The driest month is: "<<name[loSalesProduct]<<endl;
}

//Find Wettest Month
int wettestMonth (int array[])
{
	int indexOfLargest=0;

	for(int pos=1; pos<size; pos++)
	{
		if(array[pos]>array[indexOfLargest])
			indexOfLargest=pos;
	}
	return indexOfLargest;
}

//Find Driest Month
int driestMonth (int array[])
{
	int indexOfSmallest=0;

	for(int pos=1; pos<size; pos++)
	{
		if(array[pos]<array[indexOfSmallest])
			indexOfSmallest=pos;
	}
	return indexOfSmallest;
}
Oh, stupid me. I don't know what I was thinking when I said "start the counters at 1" These are arrays. >.< You had them correct the first time.


In addition there were a couple problems in the getData function. (By constantly using the constant int size 12, it was calling an element that didn't exist, instead it should have been using [count] ) It was also missing a means to combine the total rainfall. (I've added it on line 42.)

in the "for" loops, I did less than (<) the ARRAY_SIZE (12) which is the equivalent to "<=11".

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
#include <iostream>
#include <string>
using namespace std;

//Prototypes
int getData(string[], int[]);
int averageRainfall();
int driestMonth(int[]);
int wettestMonth(int[]);
void displayReport (string[],int[],int);

//Array Size
const int ARRAY_SIZE = 12;

int main()
{
	//Array Info
	string name[ARRAY_SIZE] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
	int month[ARRAY_SIZE];

	//Show Info
	cout<<"The 2010 Rain Report for Neversnows County"<<endl;
	cout<<endl;

	int totalRainfall = getData(name,month);
	displayReport(name,month,totalRainfall);
	
	return 0;
}

//Collect Data
int getData(string name[], int month[])
{
	
	int total=0;

	cout << "Please enter the amount of rainfall for each month" << endl;
	for (int count=0; count < ARRAY_SIZE; count++)
	{
		cout<< name[count] << " : ";
		cin >> month[count];
		total += month[count];
		while (month[count] < 0)
		{
			cout << "Please re-enter a positive number for the month of " << name[count] << endl;
			cin >> month[count];
		}
	}
	return total;
}

//Show The Data
void displayReport(string name[],int sales[], int total)
{
	int hiSalesProduct=wettestMonth(sales);
	int loSalesProduct=driestMonth(sales);

	cout<<"\nThe total rainfall is: "<<total<<endl;
	cout<<"The wettest month is: "<<name[hiSalesProduct]<<endl;
	cout<<"The driest month is: "<<name[loSalesProduct]<<endl;
}

//Find Wettest Month
int wettestMonth (int array[])
{
	int indexOfLargest=0;

	for(int pos=0; pos<ARRAY_SIZE; pos++)
	{
		if(array[pos]>array[indexOfLargest])
			indexOfLargest=pos;
	}
	return indexOfLargest;
}

//Find Driest Month
int driestMonth (int array[])
{
	int indexOfSmallest=0;

	for(int pos=0; pos<ARRAY_SIZE; pos++)
	{
		if(array[pos]<array[indexOfSmallest])
			indexOfSmallest=pos;
	}
	return indexOfSmallest;
}


Again, sorry about the mix up. >.< Hope this helps. ;)
Last edited on
yes it does help a lot. Thank you, this is for my final in my class so I want to make sure its perfect so I can get a 100 on it.

I have a couple more questions.
1)Could I put inches after the months and in where it displays the report?
2)What does this mean? These last two functions return the number of month with the lowest and highest rainfall amounts, not the amount of rain that fell those months
3)Does this mean that I have to have a 2-dimensional array?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
Last edited on
You won't be able to cout any strings after the user has input the rainfall for each month. (C++ automatically does a newline after cin.) You can however specify the user to input the amount in inches. (Just so they know.)

In the function displayReport(), just add ' << " inches." ' before "<< endl;"

Now I'm not sure why you used the word "sales" to refer to the month array, but on lines 59-60, you would just cout the month (sales) array in addition to the name array using the hiSalesProduct and lowSalesProduct variables in their respected lines.

Are you suppose to be using a 2D array? A 2D array is like using Word Excel. (Spreadsheets) Where you have rows and columns, a 2D array wouldn't be necessary unless you were dealing with something like the rainfall for each day of every month.

You were using a double array in your first code, but when you re-wrote it you changed it to int. (line 19.) Just change that to a double and reflect that in the formal parameters of all the functions and prototypes.
Last edited on
Now I'm not sure why you used the word "sales" to refer to the month array, but on lines 59-60, you would just cout the month (sales) array in addition to the name array using the hiSalesProduct and lowSalesProduct variables in their respected lines.


sorry I copied a program I did previously since it was kinda the same thing.

You were using a double array in your first code, but when you re-wrote it you changed it to int. (line 19.) Just change that to a double and reflect that in the formal parameters of all the functions and prototypes.


So for lines 6-10, 32, 53, 64, 77. I change all the int to double. right?

Is this how its supposed to look like? and how could I fix the average part.
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
102
#include <iostream>
#include <string>
using namespace std;

//Prototypes
double getData(string[], double[]);
double averageRainfall(double[]);
double driestMonth(double[]);
double wettestMonth(double[]);
void displayReport (string[],double[],double);

//Array Size
const int ARRAY_SIZE = 12;

int main()
{
	//Array Info
	string name[ARRAY_SIZE] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
	double month[ARRAY_SIZE];

	//Show Info
	cout<<"This program collects the rainfall totals"<<endl;
	cout<<endl;

	int totalRainfall = getData(name,month);
	displayReport(name,month,totalRainfall);
	
	return 0;
}

//Collect Data
double getData(string name[], double month[])
{
	
	int total=0;

	cout << "Please enter the amount of rainfall for each month" << endl;
	for (int count=0; count < ARRAY_SIZE; count++)
	{
		cout<< name[count] << " : ";
		cin >> month[count];
		total += month[count];
		while (month[count] < 0)
		{
			cout << "Please re-enter a positive number for the month of " << name[count] << endl;
			cin >> month[count];
		}
	}
	return total;
}

//Show The Data
void displayReport(string name[],double rain[], double total)
{
	int hiRainMonth=wettestMonth(rain);
	int loRainMonth=driestMonth(rain);
	int avgRainMonth=averageRainfall(rain);

	cout<<"2010 Rainfall Report for Neversnows County"<<endl;
	cout<<"\nThe total rainfall is: "<<total<<endl;
	cout<<"Average monthly rainfall: ";
	cout<<"The most rain fell in"<<name<< "with "<<name[hiRainMonth]<<"inches"<<endl;
	cout<<"The least rain fell in"<<name<< "with "<<name[loRainMonth]<<"inches"<<endl;
}

//Find Wettest Month
double wettestMonth (double array[])
{
	int indexOfLargest=0;

	for(int pos=0; pos<ARRAY_SIZE; pos++)
	{
		if(array[pos]>array[indexOfLargest])
			indexOfLargest=pos;
	}
	return indexOfLargest;
}

//Find Driest Month
double driestMonth (double array[])
{
	int indexOfSmallest=0;

	for(int pos=0; pos<ARRAY_SIZE; pos++)
	{
		if(array[pos]<array[indexOfSmallest])
			indexOfSmallest=pos;
	}
	return indexOfSmallest;
}

double avgRainfall(double array[])
{
	int averageofMonths=0;

	for(int pos=0; pos<ARRAY_SIZE; pos++)
	{
		pos =+ month[count];
		average=total/12;
	}
	return averageofMonths;
}
Last edited on
Well, lets go over your avgRainfall function:

1
2
3
4
5
6
7
8
9
10
11
double avgRainfall(double array[])
{
	int averageofMonths=0;

	for(int pos=0; pos<ARRAY_SIZE; pos++)
	{
		pos =+ month[count];
		average=total/12;
	}
	return averageofMonths;
}


First, you passed the month array and are referring to it as "array[]" but in your for loop your calling a array called "month[count]" the array month doesn't exist, and neither does the variable count. The variavle average doesn't exist, but averageofMonths does. the "add to self" operator is backwards, (suppose to be +=,) and your changing the counter variable, not adding to average. And the variable total also does not exist.

The line where you divide the average by 12, should be outside the loop, because it only needs to be done once, not for all 12 elements. (You could also divide by ARRAY_SIZE instead.)


When you're copying and pasting code from other projects, you need to make sure the variables are renamed to match your current program.

Edit: Oh, you also forgot to cout avgRainMonth on line 61. And you wrote "averageRainfall" instead of "avgRainfall" on lines 7 and 57. (On 57, avgRainMonth should be of type double, instead of int.) On lines 61-62, you called the name array without specifying the index, and then called the name array instead of the rain array.
Last edited on
Like this?

1
2
3
4
5
6
7
8
9
10
11
double avgRainfall(double month [])
{
	int average;

	for(int i=0; i<ARRAY_SIZE; i++)
	{
		i += month[ARRAY_SIZE];
	}
	average=i/month[ARRAY_SIZE];
	return average;
}
On line 7 you're using the counter variable (i) and adding to it itself in addition to the value in month[12] (which doesn't exist.) On line 9, you're dividing i by the value in month[12] which doesn't exist.

You can always refer to your original code in your first post. (lines 34-36.)

What line 7 should do, is add to itself (average) in addition to month[i]. (average += month[i] is the same as average = average + month[i])

After the loop, line 9 should take average, and be assigned average divided by ARRAY_SIZE, which is the number of months, 12. (average /= ARRAY_SIZE is the same as average = average / ARRAY_SIZE.)



Like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
double avgRainfall(double month [])
{
	int count=0;
	double avgRain=0;
	double rainSum=0;

	for (count =0; count <=11; count++)
	{
		rainSum = rainSum + month[ARRAY_SIZE];
	}
	avgRain = rainSum / 12;
	return avgRain;
}


When I try to run it I'm getting a lot of errors with doubles to int's. Can you show me how to write the code?
The function looks fine, except on line 9, the month array should be using the count variable, not the ARRAY_SIZE.

What does the rest of the code look like? Did you remember to change "int avgRainMonth" to "double avgRainMonth" on line 57?
Last edited on
okay, thank you.

so getData and avgRainMonth should be doubles and the rest should be int's right?
Could you explain what you mean by, "the rest should be ints"? avgRainMonth are getData() should be fine as doubles... Are you experiencing issues with getData()?
Last edited on
Here's what I've done. Can you please help me fix it and make it run?

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <iostream>
#include <string>
using namespace std;

//Prototypes
double getData(string[], double[]);
void wettestMonth(double [], char [][STRING_SIZE]);
void driestMonth(double[], char [][STRING_SIZE]);
void totalRain(double[]);
void averageRain(double[]);
void zeroArray(string []);
void displayReport (string[],double[],double);

const int NUM_MONTHS = 12;
const int STRING_SIZE = 10;

int main()
{
	//Array Info
	double rain[NUM_MONTHS];
    int count;
	 
    char months[NUM_MONTHS][STRING_SIZE] =
                { "January", "February", "March",
                  "April", "May", "June", "July",
                  "August", "September", "October",
                  "November", "December" };

	//Show Info
	cout<<"This program collects the rainfall totals"<<endl;
	cout<<endl;

	void displayReport()
	
	return 0;
}

//Collect Data
double getData(string name[], double month[])
{
	
	int total=0;

	cout << "Please enter the amount of rainfall for each month" << endl;
	for (int count=0; count < NUM_MONTHS; count++)
	{
		cout<< name[count] << " : ";
		cin >> month[count];
		total += month[count];
		while (month[count] < 0)
		{
			cout << "Please re-enter a positive number for the month of " << name[count] << endl;
			cin >> month[count];
		}
	}
	return total;
}

//Show The Data
void displayReport(string name[],double rain[], double total)
{
	    cout << "\n2010 Rain Report for Neversnows County\n";
	    cout << "----------------\n";
	 	   
	 
	   totalRain(rain);

	   averageRain(rain);

	   driestMonth(rain, months);

	   wettestMonth(rain, months);
}

void wettestMonth(double rain[], char months[][NUM_MONTHS])
{
    string month[12];
 
    zeroArray(month);
 
    double highest = rain[0];
    month[0] = months[0];
	 
    for(int i = 1; i < 12; ++i)
    {
        if(rain[i] > highest) {
            zeroArray(month);
            month[i] = months[i];
            highest = rain[i];
     }
	        else if(rain[i] == highest)
        {
            month[i] = months[i];
        }
    }
	 
    cout << "Highest Rainfall: " << highest << " inches.\n";
     

    for(int i = 0; i < 12; ++i) {
        if(month[i] != "")
           cout << "Month with highest rainfall: " << month[i] << endl;
    }
    cout << endl;
}  
	 
void driestMonth(double rain[], char months[][NUM_MONTHS])
{
    string month[12];
 
    zeroArray(month);
	 
    double lowest = rain[0];
	    month[0] = months[0];
	 
    for(int i = 1; i < 12; ++i)
    {
        if(rain[i] < lowest) {
           zeroArray(month);
           month[i] = months[i];
           lowest = rain[i];
        }
        else if(rain[i] == lowest)
        {
            month[i] = months[i];
        }
    }
	 
    cout << "Lowest Rainfall: " << lowest << " inches" << endl;
	 
    for(int i = 0; i < 12; ++i)
	{
        if(month[i] != "")
           cout << "Month with lowest rainfall: "<< month[i] << endl;
    }
    cout << endl;
}

void totalRain(double rain[])
{
   double total = 0;
   for (int index = 0; index < NUM_MONTHS; index++)
   total += rain[index];
 
    cout << "Total Rainfall: " << total << " inches.\n\n";
}

void averageRain(double rain[])
{
	
	int count=0;
	double avgRain=0;
	double rainSum=0;

	for (count =0; count <=11; count++)
	{
		rainSum = rainSum + rain[count];
	}
	avgRain = rainSum / 12;
	cout<< "Average Rainfall: " <<avgRain<<" inches. \n\n";
}
 
void zeroArray(string arr[])
{
    for(int i = 0; i < 12; ++i)
        arr[i] = "";
}
Wait, why are you suddenly using a 2D array? A 2D array isn't necessary. (Is it required for the assignment?)

Most of your issues are syntax errors, what program are you using to code? Visual Studio 2010 Express (free) has built-in syntax checking so it will underline in red what is incorrect.
Last edited on
I used a 2D array, because it says it should get the info and store it in a double array. So to me double means 2D.

Yes I'm using 2010 Express. Is what I should do? Because I need to call getData, so then it can use the info for the other stuff right?

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
int main()
{
	//Array Info
	double rain[NUM_MONTHS];
    int count;
	 
    char months[NUM_MONTHS][STRING_SIZE] =
                { "January", "February", "March",
                  "April", "May", "June", "July",
                  "August", "September", "October",
                  "November", "December" };

getData();

	cout << "\n2010 Rain Report for Neversnows County\n";
	cout << "----------------\n";
	 	   
	 
	   totalRain(rain);

	   averageRain(rain);

	   driestMonth(rain, months);

	   wettestMonth(rain, months);
}
A "double array" means it should be an array holding elements of type double. Just like you can have an array of type char, string, int, etc.

It's getting hard for me to keep up with the major changes your making in your code. (It looks completely re-written from your original code.) I'm afraid I've helped about as much as I can.

You could probably just stick with your first code (Or something close to it,) and clean up the outputted text a little. (Only changing what is cout to the screen.)
My only problem is I feel like in main, I need to call getData to get the information the user entered. So if you can help me with that and if you can find anything else wrong.

This is the program I'm going to use.
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <string>
using namespace std;

//Prototypes
double getData(string[], double[]);
void wettestMonth(double [], char [][STRING_SIZE]);
void driestMonth(double[], char [][STRING_SIZE]);
void totalRain(double[]);
void averageRain(double[]);
void zeroArray(string []);
void displayReport (string[],double[],double);

const int NUM_MONTHS = 12;
const int STRING_SIZE = 10;

int main()
{
	//Array Info
	double rain[NUM_MONTHS];
    int count;
	 
    char months[NUM_MONTHS][STRING_SIZE] =
                { "January", "February", "March",
                  "April", "May", "June", "July",
                  "August", "September", "October",
                  "November", "December" };

getData();

	cout << "\n2010 Rain Report for Neversnows County\n";
	cout << "----------------\n";
	 	   
	 
	   totalRain(rain);

	   averageRain(rain);

	   driestMonth(rain, months);

	   wettestMonth(rain, months);
}

//Collect Data
double getData(string name[], double month[])
{
	
	int total=0;

	cout << "Please enter the amount of rainfall for each month" << endl;
	for (int count=0; count < NUM_MONTHS; count++)
	{
		cout<< name[count] << " : ";
		cin >> month[count];
		total += month[count];
		while (month[count] < 0)
		{
			cout << "Please re-enter a positive number for the month of " << name[count] << endl;
			cin >> month[count];
		}
	}
	return total;
}


void wettestMonth(double rain[], char months[][NUM_MONTHS])
{
    string month[12];
 
    zeroArray(month);
 
    double highest = rain[0];
    month[0] = months[0];
	 
    for(int i = 1; i < 12; ++i)
    {
        if(rain[i] > highest) {
            zeroArray(month);
            month[i] = months[i];
            highest = rain[i];
     }
	        else if(rain[i] == highest)
        {
            month[i] = months[i];
        }
    }
	 
    cout << "Highest Rainfall: " << highest << " inches.\n";
     

    for(int i = 0; i < 12; ++i) {
        if(month[i] != "")
           cout << "Month with highest rainfall: " << month[i] << endl;
    }
    cout << endl;
}  
	 
void driestMonth(double rain[], char months[][NUM_MONTHS])
{
    string month[12];
 
    zeroArray(month);
	 
    double lowest = rain[0];
	    month[0] = months[0];
	 
    for(int i = 1; i < 12; ++i)
    {
        if(rain[i] < lowest) {
           zeroArray(month);
           month[i] = months[i];
           lowest = rain[i];
        }
        else if(rain[i] == lowest)
        {
            month[i] = months[i];
        }
    }
	 
    cout << "Lowest Rainfall: " << lowest << " inches" << endl;
	 
    for(int i = 0; i < 12; ++i)
	{
        if(month[i] != "")
           cout << "Month with lowest rainfall: "<< month[i] << endl;
    }
    cout << endl;
}

void totalRain(double rain[])
{
   double total = 0;
   for (int index = 0; index < NUM_MONTHS; index++)
   total += rain[index];
 
    cout << "Total Rainfall: " << total << " inches.\n\n";
}

void averageRain(double rain[])
{
	
	int count=0;
	double avgRain=0;
	double rainSum=0;

	for (count =0; count <=11; count++)
	{
		rainSum = rainSum + rain[count];
	}
	avgRain = rainSum / 12;
	cout<< "Average Rainfall: " <<avgRain<<" inches. \n\n";
}
 
void zeroArray(string arr[])
{
    for(int i = 0; i < 12; ++i)
        arr[i] = "";
}
Using a 2 dimensional array is going to throw everything off, because most of the function are written for only 1 dimensional arrays. (And 2D arrays are twice as complicated.)

Calling getData() without any parameter is going to result in an error because it's expecting you to pass the name and month arrays.
Pages: 12