C语言问题,求大神帮忙!!!

2024-12-29 20:42:38
推荐回答(5个)
回答1:

#include
int main()
{
const double likeSpor = 0.02;
const double goodDiet = 0.015;
double fatH,motH,youH;
char sex,spor,diet;
//处理性别
scanf("%c",&sex);
scanf("%lf",&fatH);
scanf("%lf",&motH);
scanf(" %c",&spor);
scanf(" %c",&diet);
if('m'==sex||'M'==sex)
youH=(fatH+motH)*0.54 ;
else if('f'==sex||'F'==sex)
youH=(fatH*0.923+motH)/2;
else{
printf("sex error");getch();return -1; //性别出错时
}

if('y'==spor||'Y'==spor)
{
youH=youH + youH * likeSpor ; //喜欢体育
}
if('y'=diet||'Y'=diet)
{
youH=youH + youH * goodDiet; //良好的卫生习惯
}
printf("Your future height will be %.0lf(cm)",youH);
getch(); //暂停
return 0;
}

回答2:

这样改下
if(('y'==spor||'Y'==spor)&&('y'==diet||'Y'==diet))
{
youH=youH*1.035;
}
else if(('y'==spor||'Y'==spor)&&('y'!=diet||'Y'!=diet))
{
youH=youH*1.02;
}
else if(('y'!=spor||'Y'!=spor)&&('y'==diet||'Y'==diet))
{
youH=youH*1.015;
}
只有一个会被执行

回答3:

你这个逻辑上有错误,
('y'!=diet||'Y'!=diet)
这个永远为真,应该改为
('y'!=diet&&'Y'!=diet)
实际上
if('y'==spor||'Y'==spor)
{
youH=youH*1.02;
}
if('y'==diet||'Y'==diet)
{
youH=youH*1.015;
}
这样判断就可以了

回答4:

野不清楚

回答5:

请问哪里错误?