how to solve this task

Mar 23, 2009 at 7:36am
WAP that allows the user to enter numbers till the user wants and at the end it displays the number of positive numbers, negative numbers and zeroes entered.


I have written a code but its not workin...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<stdio.h>
#include<conio.h>
void main()
{
   int n,cpos=0,cz=0,cneg=0;
   clrscr();
   printf("\nEnter a number: ");
   scanf("%d",&n);

   do
   {
      if(n>0)
        cpos++;
      if(n==0)
        cz++;
      if(n<0)
        cneg++;
   }
   while(scanf("%d",&n)!=EOF);

   printf("\nThe count of positive numbers is %d",cpos);
   printf("\nThe count of zeroes is %d",cz);
   printf("\nThe count of negative numbers is %d",cneg);

   getch();

} 
Mar 23, 2009 at 1:04pm
Line 19 do not check against EOF. scanf returns the number of arguments successfully scanned. In your case 0 or 1. EOF is neither 0 nor 1.
Mar 23, 2009 at 2:21pm
Thank U!!!
i have made the correction and now the code is working.
Topic archived. No new replies allowed.