小编use*_*024的帖子

while()循环请求正输入

我正在编写一个函数,询问用户输入,然后检查该输入是否为正数,如果不是循环,直到输入正数然后返回该值.这是我到目前为止,但当它返回即时得到一个奇怪的数字,如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)

c scanf while-loop

1
推荐指数
1
解决办法
2324
查看次数

标签 统计

c ×1

scanf ×1

while-loop ×1