Im attempting to check if the input has letters in it and if so repeat the scanf function(Specifically after the switch statement at case 1).
Its capable of detecting single characters, if a character is input the variable remains 0. However, if a number and a character are input, it takes the number and ignores the character. This is the main issue.
Wondering possible ways to filter if user inputs letters to ask the user to re-enter a number.
while (true) {
printf("Enter code 1 :");
number = 0;
scanf_s("%d", &number);
if (number == 0) {
// find the new line to recieve new input
while (fgetc(stdin) != '\n');
}
switch (number) {
case 1:
managers = 0;
printf("Managers\n");
while (managers == 0) {
managers == 0;
scanf_s("%lf", &managers);
if (managers == 0) {
managers == 0;
(printf("You have not enterd a number\n")),(fgetc(stdin) == '\n',managers==0, scanf_s("%lf", &managers));
}
}
printf("Managers have this much %.2f.\n", managers);
break;
default:
printf("Invalid entry please enter 1 or 2.");
break;
}
}
}```
man scanf? Actually, just check thescanfreturn value.