use*_*024 1 c scanf while-loop
我正在编写一个函数,询问用户输入,然后检查该输入是否为正数,如果不是循环,直到输入正数然后返回该值.这是我到目前为止,但当它返回即时得到一个奇怪的数字,如20204421.000任何帮助?
/* Checks if rate is infact positive and loops until a positive number is inputed */
int checkposrate(int rentrate)
{
while (rentrate < 0){
printf("Please enter the anual rental rate per square foot(must be positive number):");
scanf("%f",&rentrate);
}
return rentrate;
}
Run Code Online (Sandbox Code Playgroud)