user can hit enter all day long
This program works fine for the most part. If you enter 1 or 2 it says what it should, and if you enter another number it works fine as well. However, even though I implemented the method I learned on here a couple days back to clear the buffer, for some reason if you don't type a number and just hit enter, it doesn't go to default like it should. Instead, you can hit enter all day long. What's up with that?
Code:
#include <stdio.h>
int main() {
int cb;
int a;
printf("Enter an integer:");
scanf("%d", &a);
while ((cb = getchar()) != '\n');
switch (a) {
case 1:
printf("\nYou entered 1");
break;
case 2:
printf("\nYou entered 2");
break;
default:
printf("\nYou made an invalid selection!\n");
getchar();
main();
}
getchar();
return 0;
}