I'm having trouble with my school assignment. The program is suppose to ask to user to input some temperature values(which it does) then it is suppose to count the number of Hot Days (85 or <), Pleasant Days (65-84), and Cold Days (64 or >) wich it does also it also calculates the average of temperatures entered in by the user. What I can't figure out is how to print the values for Hot Days, Pleasant Days, and Cold Days. I would appreciate any help you can offer, hear is my code....
Code:
/*Program to process a collection of daily high temperatures
Written by Janelle Shew
Adapted from various course handouts and book
February 2008
Language written in C (gcc target)*/
#include <stdio.h>
#define sentinel 00
int main(void)
{
int hot = 0,
pleasant = 0,
cold = 0,
sum = 0,
count,
temp;
double average;
sum=0;
count=0;
printf("Enter temperature (00 to quit): ", sentinel);
scanf("%d", &temp);
while (temp != sentinel)
{ if (temp <= 59)
{ ++cold; }
else if (temp >= 60 && temp<= 84)
++pleasant;
else
++hot;
sum=sum+temp;
count++;
printf("Enter temperature (00 to quit): ", sentinel);
scanf("%d", &temp);
}
printf("%d Hot Days:\n", hot);
printf("%d Pleasant Days:\n", pleasant);
printf("%d Cold Days:\n", cold);
printf("%d", temp);
printf("There are %d total temperatures\n", count);
average=(double)sum/(double) count;
printf("\nAverage temperature is %8.2f\n", average);
return (0);
}
This is what the output looks like:
Enter temperature (00 to quit):45
Enter temperature (00 to quit):34
Enter temperature (00 to quit):67
Enter temperature (00 to quit):87
Enter temperature (00 to quit):89
Enter temperature (00 to quit):95
Enter temperature (00 to quit):77
Enter temperature (00 to quit):39
Enter temperature (00 to quit):00
3 Hot Days:
2 Pleasant Days:
3 Cold Days:
There are 8 total temperatures
Average temperature is 66.62