#include
typedef struct person //定义一个结构体
{
char sex;
char sports;
char diet;
float Height;
float faHeight;
float moHeight;
}person;
float Height_Element(person *p)
{
printf("性别(F/M),是否喜爱锻慧雀烂炼(Y/N),是否有良好的饮食习惯(Y/N),父亲身高,母亲身高\n");
scanf("%c %c %c %f %f",&p->sex,&p->sports,&p->diet,&p->faHeight,&p->moHeight);
if(p->sex=='F')
{
p->Height=(p->faHeight*0.923f+p->moHeight)/2;
if(p->sports=='Y')
{
p->Height=p->Height*1.02f;
if(p->diet=='Y')
p->Height=p->Height*1.02f*1.015f;
else if(p->diet=='N')
p->Height=p->Height*1.02f;
else
{
printf("输入有误!");
return -1.0f;
}
}
else if(p->sports=='N')
{
if(p->diet=='Y')
p->Height=p->Height*1.015f;
else
{
printf("输入有误!");
return -1.0f;
}
}
}
else if(p->前漏sex=='M')
{
p->Height=(p->faHeight+p->moHeight)*0.54f;
if(p->sports=='Y')
{
p->Height=p->Height*1.02f;
if(p->diet=='Y')
p->Height=p->Height*1.015f;
}
else
{
if(p->diet=='Y')
p->Height=p->Height*1.015f;
}
}
else
{
printf("输入有误!");
return -1.0f;
}
return p->Height;
}
int main()
{
float height=0;
int flag=1;
while(flag)
{
float height=0;
person p;
height=Height_Element(&p);
printf("身高为:%1.2f",height);
printf("\岁姿n继续按1,退出按0");
scanf("%d",&flag);
}
return 0;
}
我用VC编译可以运行
你最好去csdn上花rmb吧!!