如有帮助,望采纳,点击我回答右上角【采纳】按钮。
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
int result = 0;
float faHeight, moHeight, manHeight, womanHeight; //变量的声明,父母身高,用户男女身高
char sex, sports, diet; //性别,运动,饮食习惯
printf("Please enter your gender:F or M\n");
scanf("%c", &sex); //输入性别 //输入用户性别
while (sex != 'M' && sex != 'F') { //都性别输入进行判断,是否符合格式
printf("输入错误,请重新输入:\n");
fflush(stdin); //不符合,清楚缓存中的数据
scanf("%c", &sex); //重新输入
}
fflush(stdin); //清楚缓存中的数据
printf("Please enter the height of the father and mother\n");
result = scanf("%f %f", &faHeight, &moHeight); //输入父母的身高
while (result != 2) { //根据scanf()的返回值判断输入是否正确
printf("输入错误请重新输入:\n");
fflush(stdin);
result = scanf("%f %f", &faHeight, &moHeight);
}
fflush(stdin);
printf("Do you like physical exercise:Y or N\n");
scanf("%c", &sports); //是否喜欢运动
while (sports != 'Y' && sports != 'N') { //格式判断
printf("输入错误,请重新输入:\n");
fflush(stdin);
scanf("%c", &sports);
}
fflush(stdin);
printf("Do you have good eating habits:Y or N\n");
scanf("%c", &diet); //是否有良好的饮食习惯
while (diet != 'Y' && diet != 'N') { //格式判断
printf("输入错误,请重新输入:\n");
fflush(stdin);
scanf("%c", &diet);
}
fflush(stdin);
manHeight = (faHeight + moHeight) * (0.54); //计算男性身高
womanHeight = (faHeight * (0.923) + moHeight) / 2; //计算女性身高
if (sports == 'Y') { //是否喜欢运动
manHeight = manHeight * (1 + 0.02);
womanHeight = womanHeight * (1 + 0.02);
if (diet == 'Y') { //是否有良好的饮食习惯
manHeight = manHeight * (1 + 0.015);
womanHeight = womanHeight * (1 + 0.015);
}
}
if (sex == 'F') { //输入判断时男性或者女性用户
printf("Your height is %f cm", manHeight);
} else {
printf("Your height is %f cm", womanHeight);
}
return 0;
}
#include <stdio.h>
int main()
{
int i,faheight,maheight;
float h;
char sex;
scanf("%c", &sex);
scanf("%d %d",&faheight,&maheight);
if(sex=='F'){
h=(faheight+maheight)*0.54;
}
else
h=(faheight*0.923+maheight)/2;
printf("%.2f",h);
}
体育锻炼与良好的卫生习惯的怎么算呢?
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m