### rainfall dryest and wettest

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include "stdafx.h" #include #include 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):
 ``12`` ``````if(rainfall[a] < dryest) dryest = rainfall[a];``````

For wettest accordingly
 return rainfall[MONTHS];

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