Sle8课后作业问题
#include <stdio.h>int main()
{
char name;
printf("请输入你的名字:");
scanf("%s",name);
unsigned char hight;
printf("请输入您的身高(cm):");
scanf("%f",&hight);
float tizhong;
printf("请输入你的体重(kg):");
scanf("%f",&tizhong);
hight = hight / 2.54;
tizhong = tizhong / 0.453;
printf("%s的身高是%.2f(in),体重是%.2f(lb).\n",name,hight,tizhong);
return 0;
}
为啥最后打印的时候,名字不会打印出来
本帖最后由 baige 于 2020-8-8 22:55 编辑
这样试试
#include <stdio.h>
int main()
{
char name;
printf("请输入你的名字:");
scanf("%s",name);
float hight;// 用float
printf("请输入您的身高(cm):");
scanf("%f",&hight);
float tizhong;
printf("请输入你的体重(kg):");
scanf("%f",&tizhong);
hight = hight / 2.54;
tizhong = tizhong / 0.453;
printf("%s的身高是%.2f(in),体重是%.2f(lb).\n",name,hight,tizhong);
return 0;
} 本帖最后由 baige 于 2020-8-8 22:59 编辑
unsigned char hight;//你定义成了unsigned char了
scanf("%f",&hight);对于%f,是单精度浮点型flaot,
答案也是float
问题解决的话,记得给个最佳
{:10_277:}
页:
[1]