Babylonian Algo.

"Write a program that inputs an integer for n , iterates through the Babylonian algo. until guess is within 1% of the previous guess and outputs the answer as double"


Thats the question for my assignment . I just want to know how to print out guess is within 1% of the previous guess . Thanks in advanced .


After each guess, store the guess in a variable that will be used to compare to the current guess.
no i mean i got that part . i mean how do i declare it in the code to print out the guess is 1% of the previous guess :)
To print something out, use cout.

I'm guessing that wasn't what you meant though.

I'm not really sure how it works but I would do something like this:
1. Divide the guess and previous guess by the total number( Say the guess can only go up to 1000)
2. Take the absolute value of ( guess - previous ).
3. Multiple the answer by 100. ( Turn it into a percent )
4. Check to see if the answer is less than one using an if statement.

You can try something like this but it might not work.
Topic archived. No new replies allowed.