Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have written this program. It asks users for two temperatures, determines whet

ID: 3556723 • Letter: I

Question

I have written this program. It asks users for two temperatures, determines whether they are record highs or record lows and then computes the average and sticks the average into a category. If the user enters a new high or low temperature the program should be ale to update the old record high or low to the new one. How do I go about doing that. Here is my code.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

    int month = 0;
    float temp1, temp2, sum, average;
    float recordL[12] = {-14, -18, -6, 10, 23, 31, 38, 36, 26, 5, -12, -17};
    float recordH[12] = {65, 73, 77, 84, 96, 99, 102, 96, 94, 87, 75, 65};
    float averageH[12] = {43.5, 48.2, 55.9, 64.7, 74.2, 83.5, 85.9, 83.4, 77.7, 66.5, 53.1, 43.2};
    float averageL[12] = {17.5, 21.5, 26.1, 32.3, 41.0, 49.4, 54.4, 53.3, 46.5, 35.5, 24.6, 17.4};

    while(month != -1){

        //Enter month
        printf("Enter month (1-12): ");
        scanf("%d", &month);
        if(month == -1)
            break;

        //Ask user to enter temp1 and temp2
        printf("Enter temperature 1: ");
        scanf("%f", &temp1);

        printf("Enter temperature 2: ");
        scanf("%f", &temp2);


        if (temp1 < recordL[month-1]){
            printf("This is a record low for the month %d ", month);
        }
        else if (temp1 > recordH[month-1]){
            printf("This is a record high for the month %d ", month);
        }
        if (temp2 < recordL[month-1]){
            printf("This is a record low for the month %d ", month);
        }
        else if (temp2 > recordH[month-1]){
            printf("This is a record high for the month %d ", month);
        }


        if (month == 12 || month <= 2){
            printf("The season is Winter. ", month);
        }
        else if (month >= 3 && month <= 5){
            printf("The season is Spring. ", month);
        }
        else if (month >= 6 && month <= 8){
            printf("The season is Summer. ", month);
        }
        else if (month >= 9 && month <= 11){
            printf("The season is Autumn. ", month);
        }

        sum = (temp1+temp2);
        average = (sum/2);

        printf("Average: %0.2f ", average);

        if(average >= 43.2){
            printf("The average temperature falls into the 'Average High' category. ");
        }
        else if(average >= 17.5 && average <= 54.4){
            printf("The average temperature falls into the 'Average Low' category. ");
        }


    }
    return 0;
}

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int month = 0;
float temp1, temp2, sum, average;
float recordL[12] = {-14, -18, -6, 10, 23, 31, 38, 36, 26, 5, -12, -17};
float recordH[12] = {65, 73, 77, 84, 96, 99, 102, 96, 94, 87, 75, 65};
float averageH[12] = {43.5, 48.2, 55.9, 64.7, 74.2, 83.5, 85.9, 83.4, 77.7, 66.5, 53.1, 43.2};
float averageL[12] = {17.5, 21.5, 26.1, 32.3, 41.0, 49.4, 54.4, 53.3, 46.5, 35.5, 24.6, 17.4};
while(month != -1){
//Enter month
printf("Enter month (1-12): ");
scanf("%d", &month);
if(month == -1)
break;
//Ask user to enter temp1 and temp2
printf("Enter temperature 1: ");
scanf("%f", &temp1);
printf("Enter temperature 2: ");
scanf("%f", &temp2);

if (temp1 < recordL[month-1]){
printf("This is a record low for the month %d ", month);
           recordL[month-1] = temp1;
}
else if (temp1 > recordH[month-1]){
printf("This is a record high for the month %d ", month);
           recordH[month-1] = temp1;  
       }
if (temp2 < recordL[month-1]){
printf("This is a record low for the month %d ", month);
           recordL[month-1] = temp2;
}
else if (temp2 > recordH[month-1]){
printf("This is a record high for the month %d ", month);
           recordH[month-1] = temp2;
}

if (month == 12 || month <= 2){
printf("The season is Winter. ", month);
}
else if (month >= 3 && month <= 5){
printf("The season is Spring. ", month);
}
else if (month >= 6 && month <= 8){
printf("The season is Summer. ", month);
}
else if (month >= 9 && month <= 11){
printf("The season is Autumn. ", month);
}
sum = (temp1+temp2);
average = (sum/2);
printf("Average: %0.2f ", average);
if(average >= 43.2){
printf("The average temperature falls into the 'Average High' category. ");
}
else if(average >= 17.5 && average <= 54.4){
printf("The average temperature falls into the 'Average Low' category. ");
}

}
return 0;
}