Q:

calculate square root but while loop condition fails

I'm trying to learn C++ and there is a problem I am trying to work out. Basically I need to calculate the square root of a number. I think I'm on the right track, but when I run the code nothing happens after I input a number. 
int n;
    double r, intGuess, guess, ratio;

    // user input
    cout << "Enter number: ";
    cin >> n;

    intGuess = n;
    guess = n / 2;
    ratio = intGuess / guess;

    while (ratio >= 1.01 || ratio <= 0.99)
    {
        r = n / guess;
        guess = (guess + r) / 2;
    }

    cout << endl;
    cout << "The square root of " << n << " is " << guess << endl;

A:

Your loop seems to be infinite because you never update ratio inside it... then if the condition is true once, it is true forever...
It should be something like:
ratio = intGuess / guess;

while (ratio >= 1.01 || ratio <= 0.99)
{
    intGuess = guess;           // Save the previous value of guess
    r = n / guess;
    guess = (guess + r) / 2;
    ratio = intGuess / guess;   // Update ratio here with the previous and the
                                // actual value of guess
}

Also:

until guess is within 1% of the previous guess

You should save the previous guess and use this one for your ratio, not the original one.
Live example of this algorithm. I added two lines in the loop.

