tags:

views:

146

answers:

4
double sqrtIt(double x, double low_guess, double high_guess) {
    int n = 10;
    int num = 0;
    while ( n > 0.000000000000001){
     n = n / 10;
     while (num < x && low_guess <= (low_guess * 10)){
      low_guess = low_guess + n;
      num = low_guess * low_guess; 
      }
    }
    return low_guess;
}

I've tried to use the code above to find the square root of a number. the function works fine most of the time, but when the number is 2, I get the "There is no source code available for the current location. Show disassembly" error from line num = low_guess * low_guess; I don't know what did wrong, and what does show disassembly do? Thanks

+1  A: 

is there a typo in your code?
low_guess <= (low_guess * 10 ) is always true for non negative number...

+2  A: 

There are some problems with this function, but this seems to be a very strange error to get from that code. I think you made some other error somewhere else in your program, and that error is then causing this problem.

Thomas Padron-McCarthy
+2  A: 

The "no source code available" message may indicate that you are not compiling in debug mode, so your IDE can't do a source-level debug. I think there's probably some confusion here, brought on by trying to deal with an IDE for the first time...

As others have said, you should probably declare n and num to be double, not int.

Probably, once you become more familiar with your development environment (as well as the language), some of these things will sort themselves out.

comingstorm
A: 

Even if it worked it would be pretty inefficient. I guess you wanted to write something like this

double sqrtIt(double x)
{
  double guess1, guess2;
  guess1=1.0;
  do
  {
    guess2=x/guess1;
    guess1=(guess1+guess2)/2;
  }
  while (abs(guess1,guess2)<0.0000001);
  return guess1;
}
yu_sha