Scanf doesn't work at the else if part. It doesn't read the 'n' character. I can't find the reason. Any suggestion would be appreciated.
int main() {
int a, i;
char answer= '\0';
printf("Give a number: ");
scanf("%d", &a);
for(i=1; i<=a; i++) {
printf("%d\n", i);
}
printf("Run again (y/n)? ");
scanf(" %c", &answer);
if(answer == 'y' || answer == 'Y' ) {
printf("Give a number: ");
scanf("%d", &a);
for(i=1; i<=a; i++) {
printf("%d\n", i);
}
}
else if(answer == 'n' || answer == 'N' ) {
printf("Exiting...\n");
}
return 0;
}