for (int i = 0; i < 12; i++){
do {
printf(" the total rainfall for %s:", Months[i]);
scanf("%lf", &rainfallpermonth[i]);
} while (rainfallpermonth[i] < 0);
}
// Calculations
getAnnualrainfall (rainfallpermonth, MAX_Months);
sortArray(rainfallpermonth);
Maxrainfall = getMax(rainfallpermonth);
Minrainfall = getMin(rainfallpermonth);
printf ("\n The month with the highest rainfall is %s with %lf inches.\n", Months[Maxrainfall], rainfallpermonth[Maxrainfall]);
printf (" The month with the smallest rainfall is %s with %lf inches.\n ", Months[Minrainfall], rainfallpermonth[Minrainfall] );
return 0;
}
void getAnnualrainfall(double Array[], int size)
{
double Average;
double Total=0;
for (int count = 0; count < size; count++){
Total += Array[count];
}
Average = Total / size;
printf(" The total rainfall for the year is %.2lf inch\n ", Total);
printf(" The average monthly rainfall is %.2g inch\n", Average);
}
int getMax( double Arraymonths[]){
int Max= 0;
for( int i=0; i<MAX_Months; i++ ){
if( Arraymonths[i] > Arraymonths[Max])
Max = i;
}
return Max;
}
int getMin( double Arraymonths[] ){
int Min=0;
for( int i=0; i< MAX_Months; i++ ){
if( Arraymonths[i] < Arraymonths[Min])
Min = i;
}
return Min;
}
The problem is that when i execute it and type in all the number for rainfall and at the output for the month with highest and smallest rainfall, it always DEC and JAN even though its rainfall is not the highest or the smallest.. Plz help me with this as soon as possible guys since The deadline is 11:59 tonight . Thank you so much and i very appreciate that..
The problem is that you sort the array before calculating the highest and smallest rainfalls. In the sorted array the first element will always be the smallest and the last element the largest.