这个C语言怎么改?各位高手帮帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/10 22:26:09
先输入父母的身高,再输入孩子的性别,判断是男还是女,然后预测身高。 为什么我得出的程序只输入父母的身高就会出现结果?怎么输入性别呢?各位帮帮忙啊。。
#include<stdio.h>
#include<string.h>
void main()
{
float moheight,faheight,x;
printf("Please input moheight and faheight:\n");
scanf("%f%f",&moheight,&faheight);
char str[4];
printf("Please input sex:\n");
gets(str);
if (strlen(str)==3)
x=(faheight+moheight)*0.54;
else
x=(faheight*0.923+moheight)/2;
printf("%f",x);
}

下面的注释

#include<stdio.h>
#include<string.h>
void main()
{
float moheight,faheight,x;
char str[4];/*这个写在这里*/
printf("Please input moheight and faheight:\n");
scanf("%f%f",&moheight,&faheight);
getchar();/*加这个*/
printf("Please input sex:\n");
gets(str);
if (strlen(str)==3)
x=(faheight+moheight)*0.54;
else
x=(faheight*0.923+moheight)/2;
printf("%f",x);
}

要定义的啊,你前面的没定义他就不会识别的,你在float moheight,faheight,x; 下面在定义一个性别的