 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Recursion Help

1. Junior Member Join Date
Jan 2010
Posts
4

## Recursion Help

I cant get this function to recursively call itself what do i have in wrong i go through debugger and it just slides right over the recursive call

double recursive (double left, double permaRight,double permaTol, double right, double tol)
{
double leftArea, rightArea, fullArea, areaAB, finalArea=0, recursiveAreaDifference=0, midpointer;
leftArea = funcArea(F(left), F(midpoint(left,right)), midpoint(left,right),left);
rightArea = funcArea(F(right), F(midpoint(left,right)), midpoint(left,right),right);
fullArea = funcArea(F(left),F(right),(midpoint(left,right)*2),0);
areaAB = (leftArea +rightArea);
midpointer = midpoint(left,right);
finalArea += areaAB;

if(left == permaRight)//if the changing left bound = the user defined right limit
{
return finalArea; //progressive addition of the area
}

if((areaAB) <= ((fullArea + tol)||(fullArea -tol)))
{
permaTol -( fabs(areaAB - fullArea));
recursiveAreaDifference += fabs((areaAB - fullArea));
left = right;
right = permaRight;
return (recursive(left,permaRight,permaTol, right, tol));
}

else
{
return recursive(left,permaRight, permaTol, midpoint(left,right), tol/2);
}  Reply With Quote

2. Member Join Date
Feb 2009
Posts
326

## Re: Recursion Help

Thought it would be helpful if u did the following:

couple of points:
1) use code tags to place your code inside them [_code] /[_/code] without the underscore
2) pls post the min possible code required, the following functions are not defined:

F
midpoint
funcArea

3) Pls provide sample valid values to call the function recursive (provide main() function to invoke the recursive function, so that it would be a complete program)  Reply With Quote

3. Elite Member      Join Date
May 2009
Posts
2,413

## Re: Recursion Help Originally Posted by eugenesmonkey if((areaAB) <= ((fullArea + tol)||(fullArea -tol)))
Here you probably want to check whether areaAB is close to fullArea within a certain tolerance. It should look like this,

if (areaAB >= (fullArea - tol) && areaAB <= (fullArea + tol))

Note that the tolerance you're allowing is 2.0*tol. To be totally correct you probably should divide tol with 2.0 above.
Last edited by nuzzle; January 30th, 2010 at 01:46 PM.  Reply With Quote

#### Tags for this Thread

recursion, students #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
• Click Here to Expand Forum to Full Width