C中的程序未正确接收输入的问题

NP_*_*ing 2 c function

我遇到了这个程序输出的问题.它没有正确接收输入.我相信它可能与我的用户定义函数有关,它充当scanf

#include <stdio.h>
#include <math.h>
#define PI 3.14


int GetNum(void)
{
    return scanf("%d");
}

int CalculateAreaR(int length, int width)
{   
    return length*width;
}

double CalculateAreaC(int radius)
{
    return PI*radius*radius;
}

int main(void)
{
    int length;
    int width;
    int radius;
    int areaR;
    double areaC;

    printf( " Please enter the length of a rectangle  \n");
    length = GetNum();
    printf(" Please enter the width of a rectangle \n"); 
    width = GetNum();
    printf(" Please enter the radius of a circle \n");
    radius = GetNum();

    areaR = CalculateAreaR(length, width);

    printf("\nThe area of the rectangle is %d\n", areaR);

    printf("\nThe length is %d, the width is, %d and thus the area of the rectangle is %d\n\n", length, width, areaR);

    areaC = CalculateAreaC(radius);

    printf("\nThe area of the circle is %.3f\n", areaC);

    printf("\n\n The radius of the circle is %d and the area of the circle is %.3f\n\n", radius, areaC);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Gan*_*esh 8

您可以尝试修改您的程序

int GetNum(void)
{ 
   int num;
   scanf("%d", &num);

   return num;
Run Code Online (Sandbox Code Playgroud)

}