Farey/Stern-Brocot approximation to a real number

I have to create a program that approximates a real number using two endpoints (-0,1) and (1,0). I have to compute the mediant and decide whether x is smaller or larger than it, and move x accordingly. I have to keep doing this in a loop until the mediant is within 10^-6 of x. I have a basic algorithm down but I'm stuck on where to start. Any help is appreciated.

Here, the low or high endpoint which needs to be adjusted is the values stored in lowN, lowD or highN, highD.

Also, you have a do-while loop which doesn't look right.
it starts with do on line 19 and ends with the closing brace at line 46.
But the condition seems to be missing.
it should be something like:

1234

do
{
// body of loop here
} while (condition);

I think you should not output the result until after the end of that loop. Though of course during testing it can be useful to put additional cout statements in order to help understand what is going on.

One more comment, about this condition: (mediant - x > TOL)
Be careful, as the value of mediant may be either larger or smaller than x, thus the difference between the two may be either positive or negative. You may want to use the fabs() function to get the absolute value (with no sign).( fabs(mediant - x) > TOL)

Well, a variable declared inside braces { ) cannot be accessed from outside that scope. The answer is to declare all the variables before the start of the loop. I notice that mediant is declared twice, at lines 15 and 30. It should be declared just once, at line 15. And the variables int mN, mD; need to be declared somewhere around that point too.

I notice a couple of logic errors. After comparing x with the mediant at line 34, the current values of either the low or high endpoint needs to be replaced with the current mN, mD values. At the moment, the code leaves the endpoints unchanged, so the program will never terminate. The idea is that the endpoints are gradually moved closer together so that the required result is enclosed between them.

Also, I don't understand the intention behind the condition here: while(x - mN > TOL * mD);. I may be wrong, but I would have expected something more like this: while ( fabs(x - mediant) > TOL);