小编Dav*_*cek的帖子

为什么scanf需要两个数字?

我希望程序获取用户的身高和体重,然后将其输入到bmi公式中,然后输出结果.

高度问题工作正常,但是当您在重量问题中输入一个数字并按下回车键时,它只会换行.输入另一个数字后,它会将其设置为bmi并打印出来.

#include<stdio.h>

int main()
{
int h, w, bmi;

printf("What is your height (in inches)? ");
scanf("%d", &h);

printf("What is your weight? ");
scanf("%d", &w);

bmi = (w/(h*h))*703;
scanf("%d", &bmi);

printf("\t\tBMI\n");
printf("US: %d\n", bmi);
}
Run Code Online (Sandbox Code Playgroud)

c printf scanf stdio

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

标签 统计

c ×1

printf ×1

scanf ×1

stdio ×1