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

85,347

Solution 1

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;

Solution 2

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

Solution 3

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

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


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


Share:
85,347
CodeNewb
Author by

CodeNewb

Updated on July 05, 2022

Comments

  • CodeNewb
    CodeNewb almost 2 years
    #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'"...

  • CodeNewb
    CodeNewb over 10 years
    But in the for loop, x starts from "low"...?
  • CodeNewb
    CodeNewb over 10 years
    What do you mean? [Noob here...sorry :( ] The instructions say to test it by writing a main function but I should only submit one that contains only the function intergrateF...
  • Rahul Tripathi
    Rahul Tripathi over 10 years
    I didnt get that very clearly. But I think you are missing the main() function since the error which you are getting is because of that!
  • Devi K M
    Devi K M over 10 years
    but calculation of s is outside the loop na?
  • Devi K M
    Devi K M over 10 years
    double s = 1/2*exp((-xx)/2); // here value of x is not assigned.. for(x=low;x<=high;x++) { delta_x = x+delta_x; ans = ans+(delta_xs); }
  • CodeNewb
    CodeNewb over 10 years
    How do I do that? I tried setting x as 0 initially but it still doesn't work. I even tried moving the s into the loop.
  • Devi K M
    Devi K M over 10 years
    when i am trying to find the value of exp(-2), i got zero value.. and exp(2) of 7.38.. please print and check the value of s and ans inside loop
  • Devi K M
    Devi K M over 10 years
    i call this function and it is compiled .. no error.. but the ans returning is zero..
  • CodeNewb
    CodeNewb over 10 years
    How did you do it? Ok, I did: double x; double s; for(x=low;x<=high;x++) { delta_x = x+delta_x; s = 1/2*exp((-xx)/2); ans = ans+(delta_xs); printf("The integral of the function is equal to %f\n", ans);
  • CodeNewb
    CodeNewb over 10 years
    It just says "undefined reference to WinMain@16"
  • Devi K M
    Devi K M over 10 years
    from where you call this function? is it from main() ?
  • Devi K M
    Devi K M over 10 years
  • CodeNewb
    CodeNewb over 10 years
    I'm not sure what you mean by main()? How do I add that to my code? (Sorry...totally clueless)
  • Devi K M
    Devi K M over 10 years
    check it also..it may help u.. stackoverflow.com/questions/5259714/…