#include
void main()
{
char sex,sports,diet;
float faHeight,moHeight,chHeight = 0;
scanf("%c,%c,%c,%f,%f",&sex,&sports,&diet,&faHeight,&moHeight);
if(sex == 'M')
chHeight = (faHeight + moHeight)*0.54;
else if(sex == 'F')
chHeight = (faHeight*0.923+moHeight)/2;
if(sports == 'Y')
chHeight = chHeight * 1.02;
if(diet == 'Y')
chHeight = chHeight * 1.015;
printf("height = %f",chHeight);
}
手打不容易,你写的程序稍后给你分析,你先用我这个应急吧~~
输进的时候,你怎么保证N和Y是大写的?你输进Y可能输进是y,输进N可能是n ,你应该把小写 的加进到你判断的条件里面,或者把小写的改变为大写的,在进行判断;同时,你的这个程序,阅读性不怎么样,比如你可以在这么改写:
if(sports=='Y'&&diet=='Y')
{printf("height=%f", (faHeight*0.923+moHeight)/2*(1+0.035));};
if(sports=='Y'&&diet=='N')
{printf("height=%f",(faHeight*0.923+moHeight)/2*(1+0.02));};
改写如下:
if(sport=='Y'||sport=='y')
{if(diet=='Y'||diet=='y') printf("height=%f", (faHeight*0.923+moHeight)/2*(1+0.035));
else printf("height=%f",(faHeight*0.923+moHeight)/2*(1+0.02));
}