qb45advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
ABS Function Programming Example
  QuickSCREEN      Details     Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
ABS Function Programming Example
 
The following example finds an approximate value for a cube root.
It uses ABS to find the difference between two guesses to see if the
current guess is accurate enough.
 
DEFDBL A-Z
Precision = .0000001#
CLS                               'Clear the screen
INPUT "Enter a value: ", Value    'Prompt for input
'  Make the first two guesses.
X1 = 0.0# : X2 = Value
'  Go until the difference between two guesses is
'  less than the required precision.
DO UNTIL ABS(X1 - X2) < Precision
    X = (X1 + X2) / 2.0#
    ' Adjust the guesses.
    IF X * X * X - Value < 0.0# THEN
        X1 = X
    ELSE
        X2 = X
    END IF
LOOP
PRINT "The cube root is "; X
 
Sample Output
 
Enter a value: 27
The cube root is  2.999999972060323