HI, I'm writing a code for the very first time, and I'm completely stuck. Some guidance would be great.
I'm writing a C program that reads integars from file "integars.dat". The program should show how many numbers you have entered, how many among them were even, and how many were odd. Also the average of integer numbers that were odd. It should be done using nested loops, ifs whiles fors, as its a beginners program.
It does read in the integars from the FILE, and counts them properly , except it doesnt count the odd and even integars.
#include <stdio.h>
int
main (void)
{
FILE *in;
int number, s, count, w, j, status, sum, n;
double y, average;
in = fopen ("integars.dat", "r");
count = 0;
sum = 0;
average = y;
status = fscanf (in, "%d", &number);
while (status != EOF)
{
status = fscanf(in, "%d", &s);
for (j=1; j<=s; j++)
{
count = count + 1;
fscanf (in, "%lf", &y);
average = (double)sum/number;
}
fscanf(in, "%d", &w);
if (n%2==0){
printf ("There are %d even numbers.\n", w);
}
else
printf ("There are %d odd numbern.\n", w);
}
status = fscanf (in, "%d", &number);
fclose (in);
printf ("There are %d numbers in the file.\n", count);
return (0);
}
"integars.dat"
3
7
2
11
4