The first issue is that you are reading an integer value and then comparing it to a floating point. So use the simple integral value
0
for your comparison. The second issue is that if you enter a string rather than a number, then
scanf
will not return anything so
num
will contain whatever was there before. You need to capture the return value from
scanf
to check if you read a valid number. Something like:
printf("Input a number: ");
int count = scanf("%i", &num);
if (count != 1)
{
printf("Invalid Input");
}
else