这个为什么一直输出0.000000
#include
int main()
{
int sex;
float moHeight,faHeight,Height1,Height2,Height3;
char judge1,judge2;
printf("please input moHeight,faHeight,your child's sex 1 boy/0 girl\n");
scanf("%f,%f,%f",&moHeight,&faHeight,&sex);
switch(sex)
{
case1:Height1=(faHeight+moHeight)*0.54;break;
case0:Height1=(faHeight*0.923+moHeight)/2;
}
printf("if you love sports Y/N\n");
getchar();
scanf("%c",&judge1);
switch(judge1)
{
case'Y':Height2=1.02*Height1;break;
}
printf("if you have a healthy diet Y/N\n");
getchar();
scanf("%c",&judge2);
switch(judge2)
{
case'Y':Height3=1.015*Height2;break;
}
printf("your child's height is %f",Height3);
return 0;
}
11和12行case后面应该有空格,还有一些bug,帮你优化了一下
#include<stdio.h>
int main()
{
int sex;
float moHeight,faHeight,Height1,Height2,Height3;
char judge1,judge2;
printf("please input moHeight,faHeight,your child's sex 1 boy/0 girl\n");
if(3 != scanf("%f,%f,%d",&moHeight,&faHeight,&sex))
{
printf("Input error.\n");
return -1;
}
printf("mo:%.2f,fa:%.2f,sex:%d\n",moHeight,faHeight,sex);
switch(sex)
{
case 1:
Height1=(float)(faHeight+moHeight)*(float)0.54;
break;
case 0:
Height1=(faHeight*0.923+moHeight)/2;
break;
default:
printf("Input error.\n");
return -1;
}
printf("H1 %f\n",Height1);
printf("if you love sports Y/N\n");
getchar();
scanf("%c",&judge1);
switch(judge1)
{
case'Y':Height2=1.02*Height1;
break;
case'N':Height2=Height1;
break;
default:
printf("Input error.\n");
return -1;
}
printf("H2 %f\n",Height2);
printf("if you have a healthy diet Y/N\n");
getchar();
scanf("%c",&judge2);
switch(judge2)
{
case'Y':Height3=1.015*Height2;
break;
case'N':Height3=Height2;
break;
default:
printf("Input error.\n");
return -1;
}
printf("your child's height is %f\n",Height3);
return 0;
}
输入的格式是1.0,2.0,3.0这种格式吗