Thread: need help with this endless loop

1. need help with this endless loop

Hello. I'm new here as much as I'm new to C programming.

I need help with my homework. The program is supposed to process a collection of daily high temperature, and count and print the number of hot days, pleasant days, and cold days. After that, it needs to find the average temperature of entered values.

hot days temperature = 85 or higher
pleasant days temperature = 60-84
cold days temperature = under 60

I'm pretty sure my logic is off the whack, so if anyone can give me advice, it will be highly appreciated. It is giving me an endless loop and when I enter any value, the cygwin program just hangs. Thanks!

Code:
```#include <stdio.h>
#define QUIT_NUM -99

double temp, average_temp, average_temp_final;
int count_days, hot_days, pleasant_days, cold_days;

int main(void)

{

printf("Enter the temperature of any selected day.\n");
printf("Enter value -99 to quit counting\n");
scanf("%lf", &temp);
white(temp != QUIT_NUM)
{
if (temp >= 85)
++hot_days;
else if (temp <= 84 && temp >=60)
++pleasant_days;
else if (temp < 60
++cold_days;
else
printf("Value is not determinable");

}

average_temp = temp + average_temp;
count_days = hot_days + pleasant_days + cold_days;
average_temp_final = average_temp*average_temp/count_days;

printf("There were total of %f, hot_days\n");
printf("There were total of %f, pleasant_days\n");
printf("There were total of %f, cold_days\n");
printf(The average temperature between those days were %d, average_temp\n");

return(0)
}```

2. There are typos in that code which would prevent it from compiling entirely. Is it the same as the code you are using?

Anyway, your scanf line is outside the while loop -- which means you can only enter a value once, and then it just loops around with that.

3. try also indent your code better.

4. Your code is full of typos. Specially in the printf. i dont know how is ur code even compiling without errors.

5. Originally Posted by MK27
There are typos in that code which would prevent it from compiling entirely. Is it the same as the code you are using?

Anyway, your scanf line is outside the while loop -- which means you can only enter a value once, and then it just loops around with that.
no i just looked at the cygwin and typed it down because i dont know how to copy it out from cygwin. So that's probably why there are many typos.

ill try initiating the loop after the scanf statement then.

thanks for the comment