Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"...redeclared as different kind of symbol"?

#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.

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'"...

like image 367
CodeNewb Avatar asked Oct 20 '13 03:10

CodeNewb


1 Answers

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

The for loop is doing

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;

like image 78
Martin Beckett Avatar answered Oct 18 '22 12:10

Martin Beckett