0

The following C code is supposed to read a user's height. If the user enter an invalid height, such as -4, the program asks the user again. However, if the user enter a letter for example, I get an infinite loop instead of the program just asking the user again. How do I fix this?

#include<stdio.h>
#include<ctype.h>
int main(void) {
float height;
printf("Please Enter a height");
scanf("%f", &height);

while (height <= 0 || !(isdigit(height))) {
printf("Invalid height");
scanf("%f", &height);
    }
}

0 Answers0