Below is a simple program which I am trying to run, but unfortunately it doesn't work well, when I try to input for the second time, it doesn't take input.
#include <stdio.h>
int main(){
int inpt,
pos = 0,
neg = 0,
zero = 0;
char cont = 'y';
while(cont == 'y' || cont == 'Y') {
printf("\nPlease enter a Number: ");
scanf("%d", &inpt);
if( inpt < 0) {
neg++;
} else if( inpt > 0) {
pos++;
} else {
zero++;
}
fflush(stdin);
printf("\n Do you want to Continue:");
scanf("%c", &cont);
printf("\nvalue: %d", cont);
}
printf("\nTotal Number of Positive Integers: %d \n Total Number of Negative Integers: %d \n Total Number of Zeros: %d ", pos, neg, zero);
return 0;
}
Fortunately, I tried debugging and printed the value for cont and found that it's 10(which is the ASCII value for Enter key in the keyboard). I was hoping that fflush should have cleared the input buffer but that doesn't seem to be the case.
Any suggestions on how to fix would be greatly appreciated.