This question already has answers here:
Getting error: format specifies type 'int' but the argument has type 'double'
                                
                                    (2个答案)
                                
                        
                                3年前关闭。
            
                    
当我运行此C程序计算BMI时,我得到的输出始终为0
我能知道是什么问题吗?我能够得到w和h的值,但是bmi似乎总是返回0

#include <stdio.h>

int main()
{
    float w, h, bmi;
    printf("please enter your weight in kg");
    scanf("%d", &w);
    printf("please enter your height in m");
    scanf("%d", &h);

    bmi = (w/(h*h));
    printf("Your BMI is %d\n", bmi);
    return 0;

}

最佳答案

scanf("%d", &w);


应该

scanf("%f", &w);


您使用了错误的格式说明符来扫描浮点数。您应该使用%f

关于c - 我的c输出始终为0 ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40649269/

10-12 02:14