"...redeclared as different kind of symbol"?
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
low
and 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);
CodeNewb
Updated on July 05, 2022Comments
-
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 over 10 yearsBut in the for loop, x starts from "low"...?
-
CodeNewb over 10 yearsWhat 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 over 10 yearsI 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 over 10 yearsbut calculation of s is outside the loop na?
-
Devi K M over 10 yearsdouble 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 over 10 yearsHow 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 over 10 yearswhen 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 over 10 yearsi call this function and it is compiled .. no error.. but the ans returning is zero..
-
CodeNewb over 10 yearsHow 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 over 10 yearsIt just says "undefined reference to WinMain@16"
-
Devi K M over 10 yearsfrom where you call this function? is it from main() ?
-
Devi K M over 10 yearsplease check it also stackoverflow.com/questions/13459912/…
-
CodeNewb over 10 yearsI'm not sure what you mean by main()? How do I add that to my code? (Sorry...totally clueless)
-
Devi K M over 10 yearscheck it also..it may help u.. stackoverflow.com/questions/5259714/…