在这里获得以前的声明在这里错误

发布于 2025-01-21 14:00:24 字数 783 浏览 4 评论 0原文

任务:编写一个功能来计算正方形,矩形,圆的面积。 我的代码是正确的。 idk为什么我会遇到此错误完成错误

#include<stdio.h>
#include<math.h>
int square();
float airclearea();
int rectangle();
int main(){
    int s,r1,r2;
    float a;
    printf("Enter the side of square : ");
    scanf("%d",&s);
    printf("Enter the side of rectangle");
    scanf("%d %d",&r1,&r2);
    printf("Enter the radius of circle");
    scanf("%f",&a);
    printf("%d",square(s));
    printf("%d",rectangle(r1,r2));
    printf("%f",airclearea(a));
    return 0;
}
int square(int s){
  
    return s*s;
}
int rectangle(int r1, int r2){
  
    return r1*r2;
}
float airclearea(float a){
    return 3.14*a*a;
}

Task: write a function to calculate the area of a square, rectangle, circle.
My code is right. IDK why I am getting this error complete error

#include<stdio.h>
#include<math.h>
int square();
float airclearea();
int rectangle();
int main(){
    int s,r1,r2;
    float a;
    printf("Enter the side of square : ");
    scanf("%d",&s);
    printf("Enter the side of rectangle");
    scanf("%d %d",&r1,&r2);
    printf("Enter the radius of circle");
    scanf("%f",&a);
    printf("%d",square(s));
    printf("%d",rectangle(r1,r2));
    printf("%f",airclearea(a));
    return 0;
}
int square(int s){
  
    return s*s;
}
int rectangle(int r1, int r2){
  
    return r1*r2;
}
float airclearea(float a){
    return 3.14*a*a;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好久不见√ 2025-01-28 14:00:24

在MAIN之前,您在没有参数的情况下声明函数aircrearea

float airclearea();

但您正在使用类型float的参数调用该函数,

printf("%f",airclearea(a));

在这种情况下,编译器执行empers 默认参数参数proverions < /em>,在函数的情况下,类型float的参数将升级为double

因此,编译器期望使用类型double的参数定义该函数。但是该函数是用类型float的参数

float airclearea(float a){
    return 3.14*a*a;
}

定义

float airclearea( float );

double

float airclearea(double a){
    return 3.14*a*a;
}

无论如何,在参考功能之前,最好提供功能原型。

Before main you declared the function airclearea without a parameter

float airclearea();

But you are calling the function with an argument of the type float

printf("%f",airclearea(a));

In this case the compiler performs default argument promotions and in the case of the function the argument of the type float is promoted to the type double.

So the compiler expects that the function is defined with a parameter of the type double. But the function is defined with a parameter of the type float

float airclearea(float a){
    return 3.14*a*a;
}

Either declare the function before main with the parameter of the type float

float airclearea( float );

or in its definition specify the parameter as having the type double.

float airclearea(double a){
    return 3.14*a*a;
}

In any case it is always better to provide function prototypes before referencing to functions.

陈独秀 2025-01-28 14:00:24

您最初定义float airCrearea();在代码顶部附近没有参数。在代码的底部,您将其重新定义为

float airclearea(float a){
    return 3.14*a*a;
}

第一个定义定义float AirCrearea();,而无需参数。用float aircrearea(float a);替换它。您的参数是float a。您尚未显示其他错误消息,但是我假设您在int rectangle(); and int square();中遇到了相同的错误。将参数添加到这两个功能的第一个定义中,或者只需将main功能移至代码底部,然后删除前三名占位符定义。

You originally defined float airclearea(); near the top of your code as having no parameters. At the bottom of your code, you redefined it as

float airclearea(float a){
    return 3.14*a*a;
}

The first definition defines float airclearea();, without parameters. Replace it with float airclearea(float a);. Your parameter is float a. You haven't shown your other error messages, but I would assume you are getting the same error with int rectangle(); and int square();. Add parameters to the first definitions of both those functions, or just move the main function down to the bottom of your code and remove the top three placeholder definitions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文