I want to know how to keep taking inputs from keyboard with this condition: If the given input is a positive number, it keeps going with the code If the given input is a negative number or a letter, it must print "insert a positive number" and then ask again for another input until it has the correct one. About negative and positive inputs the code i wrote works great, but it bugs out when I put a letter. The check I tried is the following
chk=isalpha(n);
while(!chk || n<0)
{
printf("Inserire un intero positivo \n");
scanf("%d", &n);
chk=isalpha(n);
}
printf("%d\n%d\n", t1, t2);
In this case if I put a negative number it works correctly, but if I type a letter the printf loops. I also tried while(isalpha(n) || n<0)
And a bunch of other pieces of code I'll skip for you. Please help me figure this out