求大神指点_大神请再帮忙指点一下谢谢

原问题:大神请再帮忙指点一下谢谢
分类:编程开发 > 最后更新时间:【2017-03-29 21:41:11】
问题补充:

#include <stdio.h>

void main()

{double c,h,w,p;

char s;

printf("\n (Man please input 1,woman please input 2)\nPlease input your height,weight,sex: \n");

scanf("%lf %lf %c",&h,&w,&s);

if(s==1)

c=h-105;

else if (s==2)

c=h-107.5;

p=(w-c)/c;

if(p>=(0.1*c) && p<=(0.2*c))

printf("超重\n");

else if(p>(0.2*c) && p<=(0.3*c))

printf("轻度肥胖\n");

else if(p>(0.3*c) && p<=(0.5*c))

printf("中度肥胖\n");

else if(p<(0.2*c))

printf("偏瘦\n");

else if(p>(0.5*c))

printf("重度肥胖\n");

else

printf("正常\n");

}

我已经按您说的改了 但是运行了还是只能输出重度肥胖,这是什么回事呢,请您指点!

最佳答案

你的

if(s==1)及if(s==2)

写错了,应该是

if(s=='1')及if(s=='2')

因为它是字符,不是数值

另外你要考虑c=0的情况

如当s=='1',h=105时

c==0

p=(w-c)/c; //这个要除0错的

最佳答案由网友  whoami1978  提供
公告: 为响应国家净网行动,部分内容已经删除,感谢网友理解。
16

分享到:

其他回答

暂无其它回答!