int main(int argc, const char * argv[])
{
float faHeight = 0,moHeight = 0,childHeight = 0;
char sex = 0,exercise = 0, henlth = 0;
printf("请输入父亲的身高(cm):");
scanf("%f",&faHeight);
printf("请输入母亲的身高(cm):");
scanf("%f",&moHeight);
printf("请输入小孩的性别(男孩输入M,女孩输入F):");
getchar();
scanf("%c",&sex);
printf("是否喜爱体育锻炼('是'输入Y,'否'输入N):");
getchar();
scanf("%c",&exercise);
printf("是否有良好饮食习惯('是'输入Y,'否'输入N):");
getchar();
scanf("%c",&henlth);
switch (sex) {
case 'M':
if ( exercise =='Y'&& henlth =='N') {
childHeight = (faHeight + moHeight) * 0.54*(1 + 0.02);
}else if (exercise == 'N' &&henlth == 'Y'){
childHeight = (faHeight + moHeight) * 0.54* (1 + 0.015);
}else if (exercise == 'Y' &&henlth == 'Y'){
childHeight = (faHeight + moHeight) * 0.54*(1 + 0.02) * (1 + 0.015);
}
else {
childHeight = (faHeight + moHeight) * 0.54;
}
printf("该小孩预测身高为:%.2fcm",childHeight);
break;
case 'F':
if ( exercise =='Y'&& henlth =='N') {
childHeight = (faHeight * 0.923 + moHeight) / 2*(1 + 0.02);
} else if (exercise == 'N' &&henlth == 'Y'){
childHeight = (faHeight * 0.923 + moHeight) / 2 * (1 + 0.015);
}else if (exercise == 'Y' &&henlth == 'Y'){
childHeight = (faHeight * 0.923 + moHeight) / 2*(1 + 0.02) * (1 + 0.015);
}
else{
childHeight = (faHeight * 0.923 + moHeight) / 2;
}
printf("该小孩预测身高为:%.2fcm",childHeight);
break;
}
return 0;
}
根据父母的身高,体育锻炼,饮食习惯等,来预测孩子的身高
最新推荐文章于 2024-04-04 17:17:47 发布