这里的身高单位转化到底那里出了问题呢?
#include <stdio.h>#include <math.h>
int main ()
{
char n;
float in,kg,lb;
int cm;
printf("请输入您的姓名:");
scanf("%s",n);
printf("请输入您的身高(cm):");
scanf("%f",&cm);
printf("请输入您的体重(kg):");
scanf("%f",&kg);
printf("\n\==========正在为您转换==========\n");
in = cm/2.54;
lb = kg/0.45;
printf("%s的身高是%.2f(in),体重是%.2f(lb)。",n,in,lb);
return 0;
} 本帖最后由 jackz007 于 2019-10-16 11:31 编辑
int cm;
. . . . . .
scanf("%f",&cm);
看出问题了?
得这么改:
scanf("%d",&cm); char n;
double in, kg, lb;
double cm;
printf("name:");
scanf("%s", n);
while (getchar() != '\n');
printf("height(cm):");
scanf("%lf", &cm);
while (getchar() != '\n');
printf("weight(kg):");
scanf("%lf", &kg);
while (getchar() != '\n');
printf("\n\==========converting==========\n");
in = (double)cm / 2.54;
lb = (double)kg / 0.45;
printf("Name:%s\nheight: %lf(in)\nweight: %lf(lb)", n, in, lb);
getchar();
return 0;
You may have to clear the input{:5_91:} jackz007 发表于 2019-10-16 11:30
int cm;
. . . . . .
scanf("%f",&cm);
懂了,谢谢{:5_109:} xypmyp 发表于 2019-10-16 11:47
You may have to clear the input
第一行为什么是256呢?
页:
[1]