gpt4 book ai didi

c++ - "...redeclared as different kind of symbol"?

转载 作者:可可西里 更新时间:2023-11-01 17:54:53 29 4
gpt4 key购买 nike

#include <stdio.h>
#include <math.h>

double integrateF(double low, double high)
{
double low = 0;
double high = 20;
double delta_x=0;
double x, ans;
double s = 1/2*exp((-x*x)/2);

for(x=low;x<=high;x++)
delta_x = x+delta_x;
ans = delta_x*s;

return ans;
}

它说 low 和 high 被“重新声明为不同类型的符号”,我不知道那是什么意思。基本上,我在这里所做的一切(阅读:尝试)是从低(我设置为 0)到高(20)积分以找到黎曼和。 for 循环看起来也有点迷幻……我迷路了。

编辑:

#include <stdio.h>
#include <math.h>

double integrateF(double low, double high)
{
low = 0;
high = 20;
double delta_x=0;
double ans = 0;
double x;
double s = 1/2*exp((-x*x)/2);

for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
ans = ans+(delta_x*s);
}
return ans;
}

^在戴上牙套之后,这仍然行不通。它说“对‘WinMain@16’的 undefined reference ”...

最佳答案

您在函数内部重新定义了 low 和 high,这与参数中定义的冲突。

for循环正在做

for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
}

你是故意的吗

for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
ans = delta_x*s;
}

但是我认为你想做 ans += delta_x*s;

关于c++ - "...redeclared as different kind of symbol"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19473753/

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