Is The Weather Normal?


General Statement: Given the actual high and low temperatures for the day and the normal high and low temperatures for that day, calculate the average difference from normal.

Input: The first line of the data set for this problem is an integer that represents the number of data sets that follow. Each data set is on a separate line and consists of today’s high, today’s low, normal high, and normal low – in that order.

Output: If the average difference is negative, do not output the negative sign (-).
Output the amount of deviation from normal, followed by the words
DEGREE(S) ABOVE NORMAL, or by the words
DEGREE(S) BELOW NORMAL.
Round to 1 decimal place. A trailing zero is required if the average is an integer.
The output is to be formatted exactly like that for the sample output given below.

Assumptions: Temperatures are in the range –15..100 degrees.
The average temperature difference will not be zero.

Discussion: Determine the average of the difference of the high temperatures and the difference of the low temperatures.

Sample Input:
3
75 45 78 40
50 32 45 30
56 48 62 45

Sample Output:
1.0 DEGREE(S) ABOVE NORMAL
3.5 DEGREE(S) ABOVE NORMAL
1.5 DEGREE(S) BELOW NORMAL

Solutions :

#include <stdio.h>

int main ()
{
    int dataset;
    scanf ("%d", &dataset);

    while ( dataset-- ) {
        int today_high;
        int today_low;
        int normal_high;
        int normal_low;

        scanf ("%d %d", &today_high, &today_low);
        scanf ("%d %d", &normal_high, &normal_low);

        double lead = today_high - normal_high;;

        if ( today_low > normal_low )
            lead += today_low - normal_low;

        else
            lead += normal_low - today_low;

        if ( lead > 0 )
            printf ("%.1lf DEGREE(S) ABOVE NORMAL\n", lead / 2);
        else
            printf ("%.1lf DEGREE(S) BELOW NORMAL\n", lead / 2 * -1);
    }

    return 0;
}
Advertisements

One thought on “Is The Weather Normal?

  1. a simple program to solve this problem:

    #include
    int main(){
    float th,tl,nh,nl,average,a;
    int i,x;
    printf(“please enter the number of inputs: “);
    scanf(“%d”,&x);
    for(i=1;i<=x;i++){
    printf("please enter today's high temperature: ");
    scanf("%f",&th);
    printf("please enter today's low temperature: ");
    scanf("%f",&tl);
    printf("please enter normal high temperature: ");
    scanf("%f",&nh);
    printf("please enter normal low temperature: ");
    scanf("%f",&nl);
    average=((th-nh)+(tl-nl))/2;
    if(average<0){
    a=average*(-1);
    printf("%.1f DEGREES BELOW NORMAL.\n",a);
    }
    else{
    printf("%.1f DEGREES ABOVE NORMAL.\n",average);
    }

    }
    return 0;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s