gpt4 book ai didi

编译错误/查询

转载 作者:行者123 更新时间:2023-11-30 21:38:20 25 4
gpt4 key购买 nike

我的代码中不断出现这些错误,但我不确定它们的含义,有人可以向我解释它们的含义吗?

错误:

lab62.c: In function ‘circumfrence’:

lab62.c:7:1: error: expected ‘=’,‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘void’

lab62.c:31:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ tokenlab62.c:40:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’before ‘{’ token

lab62.c:49:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or‘attribute’ before ‘{’ token

lab62.c:55:1: error: expected ‘{’ atend of input

编辑:我刚刚向函数添加了分号,现在我收到了所有这些错误

lab62.c: In function ‘circumfrence’:

lab62.c:36:2: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float *’ [-Wformat]

lab62.c: In function ‘area’:

lab62.c:44:8: error: invalid operands to binary ^ (have ‘float’ and ‘int’)

lab62.c:45:2: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float *’ [-Wformat]

lab62.c: In function ‘volume’:

lab62.c:50:8: error: ‘v’ redeclared as different kind of symbol

lab62.c:48:19: note: previous definition of ‘v’ was here

lab62.c:52:31: error: ‘r’ undeclared (first use in this function)

lab62.c:52:31: note: each undeclared identifier is reported only once for each function it appears in

lab62.c:54:2: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘float *’ [-Wformat]

源代码:

#include <stdio.h>
#include <math.h>
#define pi 3.147

void circumfrence(float r)
void area(float r)
void volume(float r)

int main()
{
void (*f[3])(float) = { circumfrence, area, volume };
int choice;
float r;
printf("enter a value for the radius\n");
scanf("%f", &r);
printf("enter a number between 0 and 2, 3 to end: ");
scanf("%d", &choice);

while(choice >= 0 && choice < 3) {
(*f[choice])(r);
printf("enter a number between 0 and 2, 3 to end: ");
scanf("%d", &choice);
}
printf("program execution completed\n ");
return 0;
}

void circumfrence(float r)
{
float c;
printf("you wish to process the area");
printf("the radius is %f: ", r);
c = (2*r)*pi;
printf("%f", &c);
}

void area(float r)
{
float a;
printf("you wish to process the volume");
printf("the radius is %f: ", r);
a = (r^2)*pi;
printf("%f", &a);
}

void volume(float v)
{
float v;
printf("you wish to process the circumfrence");
printf("the radius is %f: ", r);
v = (4/3)*(r^3)*(pi);
printf("%f", &v);
}

最佳答案

您忘记添加一些分号 ;在代码开头的三个函数声明之后。正确的代码是这样的:

void circumfrence(float r);
void area(float r);
void volume(float r);

编辑:在第 44 行中,您不能使用 ^在 C 中得到你想要的。您可以使用a = (r*r)*pi;a = pow(r,2)*pi;另外,第 53 行也有同样的事情。

在第 50 行,您重新声明了 v多变的。 f 之间存在混淆。参数和 f多变的。您需要为 v 使用另一个名称在第 50 行。

编辑2:

当您想要打印值时,不需要使用引用。当您使用printf时,不要输入 &在变量前面。这样做:

printf("%f\n", c);
printf("%f", a);
printf("%f", v);

关于编译错误/查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10256511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com