so i want to have application that validates input. if the input was an integer/digit it will ask for number again. but if it wasnt, it will print that this is not a number and asks for number again. but before asking for number again, i want to let the user press any key to continue.
thats my code :
#include <stdio.h>
#include <math.h>
#include <conio.h>
int main() {
printf("\t\tWelcome To Prime Check App\n");
while (1) {
printf("\n\n\t[*] Enter Number: ");
int num;
int checknum = scanf_s("%d", &num);
if (checknum == 0) {
printf("\n\t[-] Not A Number!");
_getch();
}
}
}
and thats the output:
Welcome To Prime Check App
[*] Enter Number: 1
[*] Enter Number: 2
[*] Enter Number: 3
[*] Enter Number: hello
[-] Not A Number!
[*] Enter Number:
[-] Not A Number!
[*] Enter Number:
[-] Not A Number!
[*] Enter Number:
[-] Not A Number!
as you can see, it asks for a character after it prints "Not A Number" but after pressing Every button , it will also skip the scanf_s()