473,466 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

loop until two doubles differ by 0.00001

I am working on divide-and-average lab. I everything done excep the
syntax for the loop. The loop should run replaceing x with the resutls
of (x + a/x )/2 until x, and (x + a/x )/2 differ by no more than a
given amout, for example 0.00001. I've tried various ideas, the
closest I came was while(x - divavg(a, x) != 0), which more or les
sworked. It stoppend the loop when x = (x + a/x )/2, but I'm not sure
that exactly meets the goal.
Mar 11 '08 #1
2 1504
On Mar 11, 3:40 am, yogi_bear_79 <yogi_bear...@yahoo.comwrote:
I am working on divide-and-average lab. I everything done excep the
syntax for the loop. The loop should run replaceing x with the resutls
of (x + a/x )/2 until x, and (x + a/x )/2 differ by no more than a
given amout, for example 0.00001. I've tried various ideas, the
closest I came was while(x - divavg(a, x) != 0), which more or les
sworked. It stoppend the loop when x = (x + a/x )/2, but I'm not sure
that exactly meets the goal.
something like,

fabs(x-divavg(a,x)) < 0.00001;

and make it a function
Mar 11 '08 #2
On Mar 10, 10:16*pm, hurcan solter <hsol...@gmail.comwrote:
On Mar 11, 3:40 am, yogi_bear_79 <yogi_bear...@yahoo.comwrote:
I am working on divide-and-average lab. *I everything done excep the
syntax for the loop. The loop should run replaceing x with the resutls
of (x + a/x )/2 until x, *and (x + a/x )/2 differ by no more than a
given amout, for example 0.00001. *I've tried various ideas, the
closest I came was while(x - divavg(a, x) *!= 0), which more or les
sworked. It stoppend the loop when x = *(x + a/x )/2, but I'm not sure
that exactly meets the goal.

something like,

*fabs(x-divavg(a,x)) < 0.00001;

and make it a function
Thanks, while(fabs(x-divavg(a, x)) 0.00001) works fine, except it
stops one short, I've also tried a do/while same results, any syntax I
am missing so I don't have to put one more cout statement outside the
loop to catch the last iteration.
Mar 11 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: ben | last post by:
i have a bit of code, that works absolutely fine as is, but seems over complicated/long winded. is there anyway to shorten/simplify it? the code is below. description of it: it's like strcpy in...
1
by: David Veeneman | last post by:
What's the best way to compare doubles? I am testing a method that should return the fraction 2/9. For my expected result, I entered 0.222222 (a six decimal place representation of 2/9). The CLR...
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
12
by: beatjunkie27 | last post by:
I am working on a class assignment called Pennies for Pay the object of the program is to receive input for number of days worked. This should be > 0 and <= 40. An example output is below and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.