“……重新声明为不同的象征”?

时间:2021-05-12 22:42:15
#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;
}

It says that low and high are "redeclared as different type of symbol" and I don't know what that means. Basically, all I'm doing here (READ: trying) is integrating from low (which I set to 0) to high (20) to find the Riemann sum. The for loop looks kinda trippy too...I'm so lost.

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

EDIT:

编辑:

#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;
}

^That still doesn't work, after the braces and all. It says "undefined reference to 'WinMain@16'"...

在牙套和所有的牙套之后,这仍然不起作用。上面写着“未定义的‘winmain@1616’”。

6 个解决方案

#1


5  

You are redefinign low and high inside the function which * with those defined in the parameters.

你在函数中重新定义了低和高,与参数中定义的函数相冲突。

The for loop is doing

for循环正在进行。

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

did you mean it to do

你是故意的吗?

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

However I think you wanted to do ans += delta_x*s;

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

#2


0  

lowand high are already passed as parameters of your integrateF method. But they are redeclared again inside the method. Hence the error.

lowand high已经作为您的integrateF方法的参数传递。但是它们在方法中再次声明。因此,错误。

#3


0  

The error is because you are declaring low and high two times your method should be something like this

错误是因为你声明的是低和高的两倍你的方法应该是这样的。

double integrateF(double low, double high)

{
  low = 0; 
  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;

}

}

#4


0  

low and high are already passed as parameters of your integrateF method and they are redeclared again inside the method..

low和high已经作为您的integrateF方法的参数传递,并且它们在方法中再次声明。

And x is not assigned a value when it is using for the calculation of s..

在计算s时,x没有赋值。


double x, ans; double s = 1/2*exp((-x*x)/2);

双x,答;双s = 1/2 * exp((- x * x)/ 2);


#5


0  

You may want to try like this:-

你可能想这样试试:-。

for(x=low;x<=high;x++)
{                          //Use brackets since you are redefining low and high inside the function
delta_x = x+delta_x;
ans = delta_x*s;
}

or

for(x=low;x<=high;x++)
{                          //Use brackets since you are redefining low and high inside the function
delta_x = x+delta_x;
}

EDIT:-

编辑:

It says "undefined reference to 'WinMain@16'"

它说"未定义的" winmain@1616 "

Make sure you have main() or WinMain() defined. Also check that main() is not defined inside of your namespace

确保定义了main()或WinMain()。还要检查main()是否在名称空间中定义。

#6


0  

when u have declared the data type in the Parameters, you don't have to re-declare them.

当您在参数中声明数据类型时,您不必重新声明它们。

instead of

而不是

double integrateF(double low, double high)
{
    double low = 0;
    double high = 20;
    .
    .
    .
}

you should do it like this

你应该这样做。

double integrateF(double low, double high)
{
    low = 0;
    high = 20;
    .
    .
    .
}

#1


5  

You are redefinign low and high inside the function which * with those defined in the parameters.

你在函数中重新定义了低和高,与参数中定义的函数相冲突。

The for loop is doing

for循环正在进行。

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

did you mean it to do

你是故意的吗?

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

However I think you wanted to do ans += delta_x*s;

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

#2


0  

lowand high are already passed as parameters of your integrateF method. But they are redeclared again inside the method. Hence the error.

lowand high已经作为您的integrateF方法的参数传递。但是它们在方法中再次声明。因此,错误。

#3


0  

The error is because you are declaring low and high two times your method should be something like this

错误是因为你声明的是低和高的两倍你的方法应该是这样的。

double integrateF(double low, double high)

{
  low = 0; 
  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;

}

}

#4


0  

low and high are already passed as parameters of your integrateF method and they are redeclared again inside the method..

low和high已经作为您的integrateF方法的参数传递,并且它们在方法中再次声明。

And x is not assigned a value when it is using for the calculation of s..

在计算s时,x没有赋值。


double x, ans; double s = 1/2*exp((-x*x)/2);

双x,答;双s = 1/2 * exp((- x * x)/ 2);


#5


0  

You may want to try like this:-

你可能想这样试试:-。

for(x=low;x<=high;x++)
{                          //Use brackets since you are redefining low and high inside the function
delta_x = x+delta_x;
ans = delta_x*s;
}

or

for(x=low;x<=high;x++)
{                          //Use brackets since you are redefining low and high inside the function
delta_x = x+delta_x;
}

EDIT:-

编辑:

It says "undefined reference to 'WinMain@16'"

它说"未定义的" winmain@1616 "

Make sure you have main() or WinMain() defined. Also check that main() is not defined inside of your namespace

确保定义了main()或WinMain()。还要检查main()是否在名称空间中定义。

#6


0  

when u have declared the data type in the Parameters, you don't have to re-declare them.

当您在参数中声明数据类型时,您不必重新声明它们。

instead of

而不是

double integrateF(double low, double high)
{
    double low = 0;
    double high = 20;
    .
    .
    .
}

you should do it like this

你应该这样做。

double integrateF(double low, double high)
{
    low = 0;
    high = 20;
    .
    .
    .
}