在这里获得以前的声明在这里错误
任务:编写一个功能来计算正方形,矩形,圆的面积。 我的代码是正确的。 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在MAIN之前,您在没有参数的情况下声明函数
aircrearea
,但您正在使用类型
float
的参数调用该函数,在这种情况下,编译器执行empers 默认参数参数proverions < /em>,在函数的情况下,类型
float
的参数将升级为double
。因此,编译器期望使用类型
double
的参数定义该函数。但是该函数是用类型float
的参数定义
的
double
。无论如何,在参考功能之前,最好提供功能原型。
Before main you declared the function
airclearea
without a parameterBut you are calling the function with an argument of the type
float
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 typedouble
.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 typefloat
Either declare the function before main with the parameter of the type
float
or in its definition specify the parameter as having the type
double
.In any case it is always better to provide function prototypes before referencing to functions.
您最初定义
float airCrearea();
在代码顶部附近没有参数。在代码的底部,您将其重新定义为第一个定义定义
float AirCrearea();
,而无需参数。用float aircrearea(float a);
替换它。您的参数是float a
。您尚未显示其他错误消息,但是我假设您在int rectangle();
andint 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 asThe first definition defines
float airclearea();
, without parameters. Replace it withfloat airclearea(float a);
. Your parameter isfloat a
. You haven't shown your other error messages, but I would assume you are getting the same error withint rectangle();
andint square();
. Add parameters to the first definitions of both those functions, or just move themain
function down to the bottom of your code and remove the top three placeholder definitions.