C语言编程问题 帮我看看那里为什么错了
发布网友
发布时间:2022-05-10 14:13
我来回答
共2个回答
热心网友
时间:2023-10-11 09:17
错误有:
1、C语言中的%是求余,不是百分号;
2、你的字符型没有加单引号;
3、有部分语句没有加分号结束。
提示:
1、你的\n的斜杠反了;
2、你的输入必须是大写的,或许你可以改为小写也可;
你可以试一下下面的程序:
#include<stdio.h>
main()
{
char sex,sports,diet,Y,N,F,M;
double faHeight, moHeight,B,B1,B2,B3,G,G1,G2,G3;
printf("please enter sex(F/M):");
scanf("%c",&sex);
getchar();
printf("please enter faHeight and moHeight:");
scanf("%lf,%lf",&faHeight,&moHeight);
getchar();
printf("if like sports(Y/N):");
scanf("%c",&sports);
getchar();
printf("if have a good diet(Y/N):");
scanf("%c",&diet);
B=(faHeight+moHeight)*0.54;
G=(faHeight*0.923+moHeight)/2.0;
G1=(1+0.02)*(1+1.5)*G;
G2=(1+0.02)*G;
G3=(1+0.015)*G;
B1=(1+0.02)*(1+1.5)*B;
B2=(1+0.02)*B;
B3=(1+0.015)*B;
if(sex=='F'||sex=='f')
{
if(sports=='Y'||sports=='y')
{
if(diet=='Y'||diet=='y')
printf("your girl's height is=%f\n",G1);
else
printf("your girl's height is=%f\n",G2);
}
else
{
if(diet=='Y'||diet=='y')
printf("your girl's height is=%f\n",G3);
else
printf("your girl's height is=%f\n",G);
}
}
if(sex=='M'||sex=='m')
{
if(sports=='Y'||sports=='y')
{
if(diet=='Y'||diet=='y')
printf("your boy's height is=%f\n",B1);
else
printf("your boy's height is=%f\n",B2);
}
else
{
if(diet=='Y'||diet=='y')
printf("your boy's height is=%f\n",B3);
else
printf("your boy's height is=%f\n",B);
}
}
}
热心网友
时间:2023-10-11 09:17
C语言里%是取余数的双目运算符,要将百分号用小数表示,并且每条语句结束加;
#include<stdio.h>
main()
{
char sex,sports,diet,Y,N,F,M;
double faHeight, moHeight,B,B1,B2,B3,G,G1,G2,G3;
printf("please enter sex:F/M");
scanf("%c",&sex);
printf("please enter faHeight and moHeight");
scanf("%lf,%lf",&faHeight,&moHeight);
printf("if like sports:Y/N");
scanf("%c",&sports);
printf("if have a good diet:Y/N");
scanf("%c",&diet);
B=(faHeight+moHeight)*0.54;
G=(faHeight*0.923+moHeight)/2;
G1=(1+0.02)*(1+0.015)*G;
G2=(1+0.02)*G;
G3=(1+0.015)*G;
B1=(1+0.02)*(1+0.015)*B;
B2=(1+0.02)*B;
B3=(1+0.015)*B;
if(sex==F)
{
if(sports==Y)
{
if(diet==Y)
printf("your girl's height is=%f/n",G1);
else
printf("your girl's height is=%f/n",G2);
}
else
{
if(diet==Y)
printf("your girl's height is=%f/n",G3);
else
printf("your girl's height is=%f/n",G);
}
}
if(sex==M)
{
if(sports==Y)
{
if(diet==Y)
printf("your boy's height is=%f/n",B1);
else
printf("your boy's height is=%f/n",B2);
}
else
{
if(diet==Y)
printf("your boy's height is=%f/n",B3);
else
printf("your boy's height is=%f/n",B);
}
}
}