So I'm trying to make certain a user inputs a variable in a specific set of conditions for use in a later calculation. Namely, they cannot exceed vmax, not be lower than zero and not be a string.
This is what I've got.
do
{
scanf("%f", &vkmh);
if (vkmh <= vmax)
{
}
else if (vkmh < 0)
{
printf("Error, speed must be positive.\n");
}
else if (vkmh > vmax)
{
printf("Error, the max speed of this vehicle is listed as %.fkm/h.\nIt cannot exceed that value. Please enter a value under %.f.\n", vmax, vmax);
}
else if (vkm != getchar())
{
printf("Error in input. Please only use numbers\n");
}
}
while(vkmh > vmax || vkmh < 0 || vkm != getchar());
Theoretically valid values return a valid response, and a value above vmax returns an invalid response and requests the user to reenter. But a negative or a string doesn't return anything.
Any ideas on how I can get this to work?