C语言程序设计,身高的计算。请各位帮忙看看我的程序,多谢了!

2025-05-17 17:16:31
推荐回答(1个)
回答1:

//顺序不对

#include
int main()
{
char sex,sports,diet;
float faheight,moheight,height;

printf("faheight="); //输入的单位以公斤计算
scanf("%f", &faheight); //输入的单位以公斤计算
printf("moheight=");
scanf("%f", &moheight);
printf("Male or Famale?Please input 'M' or 'F':");
scanf("%1s", &sex);
switch(sex)
{
case'F':height=(faheight+moheight)*0.54;break;
case'M':height=(faheight*0.923+moheight)/2;break;
}
printf("Do you like sports?please input'Y' or 'N':");
scanf("%1s", &sports);
switch(sports)
{
case'Y':height=height*(1.02);break;
case'N':height=height;break;
}
printf("Do you have good diet and habits?please input'Y' or 'N':");
scanf("%1s", &diet);
//分析判断预测
switch(diet)
{
case'Y':height=height*(1.015);break;
case'N':height=height;break;
}
printf("\nmy height is:%.3f",height);

return 0;
}