关于#c语言#的问题,请各位专家解答!


//算孩子身高

#include<stdio.h>
#define HEG 0.54
float height(float father, float mother);

int main()
{
    float father;
    float mother;
    float son;

        printf("请输入父亲的身高:\n");
        scanf_s("%f", &father);

    printf("请输入母亲的身高\n");
    scanf_s("%f", &mother);

        son = height(father, mother);
    printf("预测孩子的身高:");
    printf("%.2f\n",son);
    return 0;
}
float height(float father,  float mother)
{
    float son =(mother + father)*HEG;
    return 0;
}

img


为什么答案一直是0?
本人零基础刚看一天书

那个函数返回值改一下就行了。

 
//算孩子身高
 
#include<stdio.h>
#define HEG 0.54
float height(float father, float mother);
 
int main()
{
    float father;
    float mother;
    float son;
 
        printf("请输入父亲的身高:\n");
        scanf("%f", &father);
 
    printf("请输入母亲的身高\n");
    scanf("%f", &mother);
 
        son = height(father, mother);
    printf("预测孩子的身高:");
    printf("%.2f\n",son);
    return 0;
}
float height(float father,  float mother)
{
    float son =(mother + father)*HEG;
    return son;
}

第28行:return 0; 改为: return son;