The solution starts out very coarse and will be "stepwise refined". 

The solution starts out very coarse
Rewriting algorithm with program constructs
leftPoint = 0; rightPoint = 10; while ( rightPoint  leftPoint >= 0.000001 ) { if ( solution is in left halft of interval ) { leftPoint = leftPoint; // This statement is unnecessary... rightPoint = (leftPoint + rightPoint)/2; } else { leftPoint = (leftPoint + rightPoint)/2; rightPoint = rightPoint; // Also unnecessary... } } 
Consider:
Rewriting algorithm using sign difference to characterize location of solution:
leftPoint = 0; rightPoint = 10; while ( rightPoint  leftPoint >= 0.000001 ) { midPoint = (leftPoint + rightPoint)/2; if ( function value of midPoint & leftPoint have different sign ) { // Solution is in left half of interval rightPoint = midPoint; // new rightPoint } else { // Solution is in right half of interval leftPoint = midPoint; // new leftPoint } } 
Rewriting algorithm with function value computation:
leftPoint = 0; rightPoint = 10; while ( rightPoint  leftPoint >= 0.000001 ) { midPoint = (leftPoint + rightPoint)/2; y_midPoint = f(midPoint); y_leftPoint = f(leftPoint); if ( (y_midPoint < 0 && y_leftPoint > 0)  (y_midPoint > 0 && y_leftPoint < 0) ) { // Solution is in left half of interval rightPoint = midPoint; // new rightPoint } else { // Solution is in right half of interval leftPoint = midPoint; // new leftPoint } } 
Here is a DEMO program:
click here
Notice the static method I used to compute
function value