Babylonian Algo.

Mar 26, 2009 at 1:23pm
"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 .


Mar 26, 2009 at 3:07pm
After each guess, store the guess in a variable that will be used to compare to the current guess.
Mar 27, 2009 at 12:20pm
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 :)
Mar 27, 2009 at 12:35pm
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.