I'm supposed to make a program that reads off a txt file called integers.txt. It reads the numbers and tells the user "how many numbers you have entered, how many among them were even, and how many were odd. The program must also display the average of integer numbers that were odd." I wrote the code below. It runs but for some reason it keeps saying that I have zero numbers, zero even numbers, zero odd numbers etc. I don't know what's wrong. Can someone please help me out? Thanks.
Code:
#include <stdio.h>
int
main (void)
{
int number, e, o, s, average;
FILE *integers;
integers = fopen ("integers.txt", "r");
/*initialization*/
e = 0;
o = 0;
/* read number by number until the end of file */
while (fscanf (integers, "%d", &number) !=EOF)
{
if (number%2 == 0)
e = e + 1;
else
o = o + 1;
}
fclose (integers);
/* final report */
s = e + o;
printf ("There are %d numbers in the file.\n", s);
printf ("The total number of even numbers numbers is %d.\n", e);
printf ("The sum of all the odd numbers numbers is %d.\n", o);
average = o / e;
printf("The average number of odd number is %d\n.", average);
return (0);
}