//5.11
int main()
{
float Height=0.0;
float faHeight=0.0;
float maHeight=0.0;
char sex;
char diet;
char sports;
printf("What's your child's sex?a boy(M)or a girl(F):");
scanf("%c", &sex);
printf("Please enter father's height:");
scanf("%f", &faHeight);
printf("Please enter mather's height:");
scanf("%f", &maHeight);
printf("If your child like sports(Y/N):");
scanf(" %c", &sports);
printf("If your child have a good diet(Y/N):");
scanf(" %c", &diet);
if (sex=='M' && diet=='Y'&&sports=='Y')
{
Height = (faHeight + maHeight) * 0.54 * 1.02 * 1.015;
printf("Your child's height may %.2f tall",Height);
}
else if (sex == 'M' && diet == 'Y' && sports == 'N')
{
Height = (faHeight + maHeight) * 0.54 * 1.015;
printf("Your child's height may %.2f tall", Height);
}
else if (sex == 'M' && diet == 'N' && sports == 'Y')
{
Height = (faHeight + maHeight) * 0.54 * 1.02 ;
printf("Your child's height may %.2f tall", Height);
}
else if (sex == 'M' && diet == 'N' && sports == 'N')
{
Height = (faHeight + maHeight) * 0.54;
printf("Your child's height may %.2f tall", Height);
}
else if (sex == 'F' && diet == 'Y' && sports == 'Y')
{
Height = (faHeight * 0.923 + maHeight) / 2 * 1.02 * 1.015;
printf("Your child's height may %.2f tall", Height);
}
else if (sex == 'F' && diet== 'N' && sports == 'Y')
{
Height = (faHeight * 0.923 + maHeight) / 2 * 1.02;
printf("Your child's height may %.2f tall", Height);
}
else if (sex == 'F' && diet == 'Y' && sports == 'N')
{
Height = (faHeight * 0.923 + maHeight) / 2 * 1.015;
printf("Your child's height may %.2f tall", Height);
}
else if (sex == 'F' && diet == 'N' && sports == 'N')
{
Height = (faHeight * 0.923 + maHeight) / 2;
printf("Your child's height may %.2f tall", Height);
}
else
{
printf("error");
}
return 0;
}
c语言程序设计苏小红课后习题答案5.11
于 2022-03-20 11:43:46 首次发布