我试着做一个简单的程序来计算体重指数,但是扫描总是返回0.00000,不管我怎么做。我到处找,试了很多东西,
谢谢大家。

#include <stdio.h>
#include <stdlib.h>


int main() {
    float height;
    float initialheight;
    float weight;
    float bmi;
    float nothing;

    printf("What's your weight? ");
    scanf("%lf", &weight);
    printf("%f", &weight);

    printf("What's your height? ");
    scanf("%lf", &initialheight);
    printf("%f", &initialheight);

    height = (initialheight * initialheight);
    printf("%f", &height);

    bmi = (weight / height);
    printf("Your BMI is ");
    printf("%f", &bmi);

    scanf("%f", nothing); //just to keep the program open
    return 0;
}

最佳答案

你得改变两件事。首先,将printf("%f", &weight)更改为printf("%f", weight)。同时将scanf("%lf", &weight)更改为scanf("%f", &weight)将使您的程序运行良好。

关于c - Scanf总是返回0.000000,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26834915/

10-11 22:13
查看更多