新手,循环问题,自动循环两次
一个循环问题,是个计算身高的程序,我加循环的时候出现这种情况,就是,第二次之后,自动循环两次,(这是只用while(1)写的)#include <stdio.h>
int main()
{
char sex;
double faHeight,moHeight,height;
char sports,diet;
int i;
while(1)
{
printf("please input sex(f/m),sports(y/n),diet(y/n),father's height,mother's height\n");
scanf("%c,%c,%c,%lf,%lf",&sex,&sports,&diet,&faHeight,&moHeight);
if(sex=='f')
if(sports=='y')
if(diet=='y')
height=(faHeight*0.923+moHeight)/2*1.035;
else
height=(faHeight*0.923+moHeight)/2*1.02;
else if(diet=='y')
height=(faHeight*0.923+moHeight)/2*1.015;
else
height=(faHeight*0.923+moHeight)/2;
else
if(sports=='y')
if(diet=='y')
height=(faHeight+moHeight)*0.54*1.035;
else
height=(faHeight+moHeight)*0.54*1.02;
else if(diet=='y')
height=(faHeight+moHeight)*0.54*1.015;
else
height=(faHeight+moHeight)*0.54;
/* if(sex=='m')
result=faHeight+moHeight)*0.54;
else if(sex=='f')
result=(faHeight*0.923+moHeight)/2.0;
if(sports=='y')
result*=1.02;
if(diet=='y')
result*=1.015; */
printf("your height is %.1f\n",height);
printf("继续 1 退出 0\n");
scanf("%d",&i);
if(i==0)
break;
}
return 0;
}