初学C语言,可能一些变量取名不够规范,还望多多指教!
具体代码如下:
#include <stdio.h>
struct Horse
{
unsigned int sex;
double faHeight;
double moHeight;
unsigned int PT;
unsigned int Eh;
char name[20];
};
int main(void)
{
struct Horse dobbin;
double chdHeight = 0.0;
printf("\n请输入孩子的姓名:");
scanf("%s", dobbin.name);
printf("\n请输入%s的性别:输入 1 代表男,输入 0 代表女!", dobbin.name);
scanf("%d", &dobbin.sex);
printf("\n请输入%s父亲的身高(单位:cm):", dobbin.name);
scanf("%lf", &dobbin.faHeight);
printf("\n请输入%s母亲的身高(单位:cm):", dobbin.name);
scanf("%lf", &dobbin.moHeight);
printf("\n请输入%s是否喜爱体育锻炼:输入 1 代表是,输入 0 代表否!", dobbin.name);
scanf("%d", &dobbin.PT);
printf("\n请输入%s是否有良好的饮食习惯:输入 1 代表是,输入 0 代表否!", dobbin.name);
scanf("%d", &dobbin.Eh);
chdHeight = (dobbin.sex ? (dobbin.faHeight + dobbin.moHeight) * 0.54 : (dobbin.faHeight * 0.923 + dobbin.moHeight) / 2) *
(dobbin.PT ? (1 + 0.02) : 1) * (dobbin.Eh ? (1 + 0.015) : 1);
printf("\n%s成人后的身高预测为:%.2lfcm", dobbin.name, chdHeight);
return 0;
}