ever hear about something called the "principle of the excluded third" sometimes known as "The law of the excluded middle"?
lets look at a simple example:
CODE
int func(int a, int b) {
if (a>b) {
return a;
} else {
return b;
}
return a*b; //this never happens!
}
the function never returns a*b because either a > b (return a) or it isn't (return b)... there is no 3rd option that jumps over the if-statement and return a*b. This is exactly what happens to the line
return guess; in your program.
You seem to be using some sort of bisection to find your value. But I don't understand your error term. normally in bisection you have a tolerance value epsilon and if (high - low) <= epsilon then you return a the current guess of (high + low)/2.
Here is the basic procedure for bisection:
inputs: low = lower bound, high = upper bound, epsilon - measure of minimum interval.
B1 guess = (high - low)/2
B2 if (high - low) <= epsilon then return guess as the approximation.
B3 if sign(f(high))*sign(f(guess)) <= 0 then low = guess else high = guess goto B1.
in this case f(x) = x*x - value.
Another note... your interval for number between 0 and 1 is wrong... note the at sqrt of .1 is 0.31622 which is not in the interval (0, .1). I would just make this interval (0, 1) for all values that that range.