Hey guys,
I am stuck on a question in my C Programming Book and i was wondering if you guys can help anyways...
I need to write a program using a while/do-while/for loop command that counts positive and negative numbers in a list of integers from a file
eg.
5 (total number of integers in the list)
2
-3
4
7
-9
Ok I have...
Code:
int a, b, c, d, e, numbers;
int positives, negatives;
FILE *input;
input=fopen ("C:\\hw4-1in.dat.txt.", "r");
fscanf(input, "\r%d\n", &numbers);
printf( "%d", numbers);
fscanf(input, "%d\n", &a);
printf( "%d", a);
fscanf(input, "%d\n", &b);
printf( "%d", b);
fscanf(input, "%d\n", &c);
printf( "%d", c);
fscanf(input, "%d\n", &d);
printf( "%d", d);
fscanf(input, "%d\n", &e);
printf( "%d", e);
fclose(input);
if (a>0)
{
positives=1+positives;
}
else if (a<0)
{
negatives=1+negatives;
}
if (b>0)
{
positives=1+positives;
}
else if (b<0)
{
negatives=1+negatives;
}
if (c>0)
{
positives=1+positives;
}
else if (c<0)
{
negatives=1+negatives;
}
if (d>0)
{
positives=1+positives;
}
else if (d<0)
{
negatives=1+negatives;
}
if (e>0)
{
positives=1+positives;
}
else if (e<0)
{
negatives=1+negatives;
}
printf ("The total number of the positive integers is \n %d", positives);
printf ("The total number of the negative integers is \n %d", negatives);
}
It keep saying windows encountered a problem when i run it...
Any help would be appreciated thanks!!