Stats class array problems

I have 3 files of a Rainfall/Stats class and I am having problems with array, it is not getting the input and making the total,average,etc not work and giving them 0's or garbage.
I will appreciate any help and thanks in advance.

This is the implementation file.

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
#include "Stats.h"
#include <iostream>
using namespace std;
Stats::Stats()
{
	for(int index = 0; index < MONTHS; index++)
	{
		rainfall[index] = 0;
	}
}

void Stats::setValue(int months, double rain)
{
		if(rain >= 0)
		{
			rainfall[months] = rain;
		}
		else
		{
			rainfall[months] = 0;
		}
}

double Stats::getTotal()
{
	double total = 0.0;
	for(int index = 0; index <MONTHS; index++)
	{
		total += rainfall[index];
	}
	return total;
}

double Stats::getAverage()
{
	double total = getTotal();
	double average = total / ((double)MONTHS);
	
	return average;
}

double Stats::getMax()
{
	double max = rainfall [0];
	for(int index = 0; index <MONTHS; index++)
	{
		if(rainfall[index] > max)
		{
			max = rainfall[index];
		}
	}
	return max;
}

double Stats::getMin()
{
	double max = rainfall [0];
	for(int index = 0; index < MONTHS; index++)
	{
		if(rainfall[index] < min)
		{
			min = rainfall[index];
		}
	}
	return min;
}



This the the actual program that runs the header and implementation files.
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
#include "Stats.h"
#include <iostream>


using namespace std;
const int MONTHS = 12;

int main()
{
	Stats raindata;
	double rain;

	cout << "Enter the data for each the month."<<endl;
	for(int index = 0; index < MONTHS; index++)
	{
		cout << "Month " <<(index +1) << ": ";
		cin >>rain;
		raindata.setValue(index, rain);
	}

	cout << "Total amount of Rain is " << raindata.getTotal() <<endl
		 << "Average amount of Rain is " << raindata.getAverage() <<endl
		 << "The Max amount of rain was " <<raindata.getMax() <<endl
		 << "The Mininum amount of rain was " <<raindata.getMin() <<endl; 

	system("pause");
	return 0;
}
Well your code didn't compile until I fixed the first line in getMin() but after that it worked fine.
yeah after a couple of min I saw that and changed a few other lines now i got it to work thanks for the respond though I greatly appreciate it.
Topic archived. No new replies allowed.