Hi, the program that I'm trying to run is simple, but im still having a bit of trouble figuring out the while loop function.
The program runs like so:
Find out the average temperature from an input, using while loop of course.
example: 98, 87, 50, 90, 87, 50
average = 77
77 = Pleasant Day..
-----------------------------------------------------------------------
The problem with the program is that it only stops at the first input... and does nothing more.
#include <stdio.h>
#include <math.h>
int
main(void)
{
int temp; // temperature of the day
int x = -1;
int total = 0;
printf("Input the temperature -> \n Input 999 to stop -> \n");
scanf("%d", &temp);
while (temp != 999){
total = temp + total; // adds up the temperature
x++;
}
total = total / x; //solves the average devides the total by the number of temperature
if (total >= 85)
printf("Hot Day\n");
else if (total >= 60 && total <= 84)
printf("Pleasant Day\n ");
else
printf(" Cold Day\n");
return 0;
}
Also I've realized that the problem might be in this line of code ->
while (temp != 999){
total = temp + total; // adds up the temperature
[u]x++;[/u]
}
Since the x++ doesn't have anything to do with it, I wanted to know how I could make it interact with the statement.
Also thank you in advance