#include <stdio.h>
int main() {
float faHeight, moHeight, Height
char sex, sports, diet
printf("父亲的身高:")
scanf("%f", &faHeight)
printf("母亲的身高:")
scanf("%f", &moHeight)
printf("小孩的性别:")
scanf(" %c", &sex)
if (sex == 'F') {
Height = (faHeight * 0.923 + moHeight) /察塌 2
} else if (sex == 'M') {
Height = (faHeight + moHeight) * 0.54
} else {
printf("Warning")
return 0
}
printf("是否喜欢体育锻炼:")
scanf(" %c", &sports)
if (sports == 'Y') {
Height *= 1.02
}
printf("是否有良好的饮食习惯:")
scanf(" %c", &diet)
if (diet == 'Y') {
Height *= 1.015
}
printf("小孩的身高预测为:%.2fcm\n", Height)
return 0
}
注意,scanf函数在败姿圆读取字符时需要在格式字符串前加一个空格,以消耗掉输入缓冲区中的换行符。
#include <stdio.h>int main(void)
{
float faHeight,moHeight,chHeight
printf("父亲的身高(cm):")
scanf("%f",&faHeight)
printf("母亲的侍雹身高(cm):")
scanf("%f",&moHeight)
printf("孩子的性别(M/F):")
getchar()
if(getchar() == 'M'){
chHeight = (faHeight + moHeight ) * 0.54
}else if(getchar() == 'F'){
镇灶 chHeight = (faHeight * 0.923 + moHeight)/2
}else{
chHeight = 0
}
老旅帆 getchar()
printf("是否喜爱体育锻炼(Y/N):")
if(getchar() == 'Y'){
chHeight *= 1.02
}
getchar()
printf("是否有良好的卫生饮食习惯(Y/N):")
if(getchar() == 'Y'){
chHeight *= 1.015
}
printf("预测的身高:%dcm\n",(int)(chHeight + 0.5))
return 0
}
问题较多,帮你改了,再试试int
main()
{
double
f,m,y
int
f,m,y,n
char
sex,sports,diet
printf("请输入父亲身高:")
scanf("%lf",&f)
printf("请输入母慎乱亲身高:")
scanf("%lf",&m)
fflush(stdin)
printf("sex(f
,
m):")
scanf("%c",&sex)
fflush(stdin)
printf("sports(y
,
n):")
scanf("%c",&sports)
fflush(stdin)
printf("diet(y
,
n):")
scanf("%c",&diet)
//scanf("渗孝神%lf\n",&y)
这句应该没用!
if
(sex=='m'
)
y=(f+m)*0.54
else
//
if
(sex=='f'
)
非男即女丛亏,这个if也没用
y=(f*0.923+m)/2
if
(sports=='y')
y=y*(1+0.02)
if
(diet=='y')
y=y*(1+0.015)
printf("y=%lfcm\n",y)
return
0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)