I have the following code to ask a user for input (lowWarp). The input must be from 1.0 to 10.0. If I enter, say, 0.2, it allows me to attempt entering another value. However, if I enter something like 1/2 or asdf it starts endlessly looping. How do I prevent this and instead allow a proper value to be entered?
while (badData == true)
{
printf("Enter the low warp factor; warp factor = \n");
scanf_s("%f", &lowWarp);
if (lowWarp < 1.0 || lowWarp > 10.0) //Determines if number is between 1.0 - 10.0
{
badData = true;
printf("Invalid input! Range is 1.0 - 10.0.\n");
lowWarp = 0.0;
}
else
{
badData = false;
}
}