I'm trying to execute below program where user enters numbers until he wishes, but my second scanf() is getting skipped. i tried giving scanf("%[^\n]d",&ans) but it doesn't work. Fflush(stdin) doesn't work in netbeans. please help and explain why it is happening.
int Ch5BG()
{
int number,positive,negative,zero;
char ans='y';
positive=negative=zero=0;
while(ans=='y'||ans=='Y')
{
printf("Please enter a number:\n");
scanf("%d",&number);
if(number>0)
positive++;
if(number<0)
negative++;
if(number==0)
zero++;
printf("Do you want to continue:");
scanf("%c",&ans);
}
printf("The number of positives entered are:%d",positive);
printf("The number of negatives entered are:%d",negative);
printf("The number of zeros entered are:%d",zero);
return 0;
}
The output would be as below :
Please enter a number:
3
Do you want to continue:The number of positives entered are:1The number of negatives entered are:0The number of zeros entered are:0
RUN SUCCESSFUL (total time: 1s)