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
|
#include<iostream>
using namespace std;
int main(){
int size_col = 12;
int size_row = 12;
char months_array[12][12] =
{ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October"
, "November", "December" };
int const rain_size = 12;
double rainfall_array[rain_size];
int count1, count2;
double sum_total = 0, average = 0;
char highest, lowest;
double check_low, check_high;
for (count1 = 0; count1 < size_col; count1++){
cout << "Enter the rainfall for " << months_array[count1]<< endl;
cin >> rainfall_array[count1];
if (rainfall_array[count1] < 0){
do {
cout << "Invalid input, enter a positive number" << endl;
cin >> rainfall_array[count1];
} while (rainfall_array < 0);
}
}
check_low = rainfall_array[0]; //to compare the first array with others
check_high = rainfall_array[0];
for (count2 = 0; count2 < rain_size; count2++){
sum_total = rainfall_array[count2] + sum_total;
average = (sum_total / rain_size);
if (rainfall_array[count2] < check_low){
lowest = months_array[count2]; //This is the problem
}
if (rainfall_array[count2] > check_high){
highest = months_array[count2]; //and here
}
}
cout << "The total rainfall of the year is " << sum_total << endl;
cout << "The average rainfall of the year is " << average << endl;
cout << "The month with the highest rain fall is " << highest << endl;
cout<< "The month with the lowest rain fall is " << lowest << endl;
system("pause");
return 0;
}
|