need help with a for loop
What I am trying to do is select the number of days that I want to add temperatures. So if I type in 6, then I want to be able to type in 6 temperatures individually, one after the other. However, once I type in the first one and hit enter, the for loops skips through the remaining 5. Once I am able to type in the temperatures for the amount of days I select, I need to calculate the avg temps for those days and display it. Here is my code. Any help would be greatly appreciated. Tommy
[CODE]
#include <stdio.h>
#include <conio.h>
int main()
{
int count, days;
float temp, total, avg;
total=0.0;
printf("\nPlease enter the number of days temperatures you wish to enter: ");
scanf("%d", &days);
for (count=0;count<days;++count)
{
printf("\nTemperature is: ");
scanf("%.2f", &temp);
total=total+temp;
}
avg=total/days;
printf("\n\nThe average temperature was: %5.2f\n", avg);
getch();
return 0;
}
Here is the results so far:
Please enter the number of days temperatures you wish to enter: 6
Temperature is: 54.3
Temperature is:
Temperature is:
Temperature is:
Temperature is:
Temperature is:
The average temperature was: -107374176.00
I now only need to add the temps. Do I need another printf or scanf statement? Thanks again for your help.....
CODE]