ok so i have changed a few things and have my program running and working almost perfectly. i am haveing 2 problems. there are 30 temperatures in my file, yet my program says there are 31, also my average is off by about a .5, i thought that it might have something to do with the count being off, but even computing the average with the incorrect count, the average is still off by a little. here is my code if anyone has any suggestions or hints. thanks
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char inFileName[160];
int x;
int tempcount = 0;
int max = 0;
int min = 10000;
double sum = 0;
FILE *tempsIn;
printf("Temperature Analyzer v1.1\n");
printf("\n");
printf("What file to analyze?\n");
scanf("%s",&inFileName);
tempsIn = fopen("c:\\documents and settings\\christina kestler\\desktop\\temps.txt", "r");
if (inFileName == NULL) {
printf("File could not be opened.\n");
system("pause");
exit(EXIT_FAILURE);
}
while(!feof(tempsIn))
{
fscanf(tempsIn,"%d",&x);
tempcount++;
sum += x;
if(x > max)
max = x;
if(x < min)
min = x;
}
double avg = sum / tempcount;
printf("# of daily temps: %d\n", tempcount);
printf("Average daily temp: is %0.5lf\n", avg);
printf("Highest temp: %d\n", max);
printf("Lowest temp: %d\n", min);
system("PAUSE");
return 0;
}