rainfall dryest and wettest

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

int getRainfallData(int [], string [], int);

int getRainfallData(int rainfall[], string monthName[], int MONTHS)
{
	double totalRainfall = 0;
	double averageRainfall = 0;
	string wettest;
	string dryest;

	for (int a = 0 ; a < MONTHS ; a++)
	{
		cout << "Enter the amount of rainfall for " << monthName[MONTHS] << ": ";
		cin >> rainfall[MONTHS];
	}

	for (int b = 0 ; b < MONTHS ; b++)
	{
		totalRainfall = totalRainfall + rainfall[MONTHS];
		averageRainfall = totalRainfall / 12;
	}

	cout << "\n";
	cout << "The total rainfall amount of rainfall is " << totalRainfall << endl;
	cout << "The average ammount of rainfall is " << averageRainfall << endl;

	return rainfall[MONTHS];
}

int main()
{
	const int MONTHS = 12;
	int rainfall[MONTHS];
	string monthName[MONTHS] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

	getRainfallData(rainfall, monthName, MONTHS);

	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}


How can i make it calculate and wettest and dryest month also.

dyest = the month with the least amount of rainfall
wettest = the month with the most amount of rainfall
Last edited on
You don't need two loops. your calculation may take place after the value is entered.

line 18: cin >> rainfall[a];
line 23: totalRainfall = totalRainfall + rainfall[b];
line 24 doesn't belong within the loop.


How can i make it calculate and wettest and dryest month also.
Introduce to more variables (like wettest and dryest):
1
2
if(rainfall[a] < dryest)
  dryest = rainfall[a];

For wettest accordingly
return rainfall[MONTHS];

Also it causes a crash.
Topic archived. No new replies allowed.