bas7ex.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 and DEFtype Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example finds the cube root of an input value. It uses the
'ABS function to test if the current guess is accurate. The DEFDBL
'statement is used to establish the default for the variables.
 
DEFDBL A-Z
Precision = .0000001#
CLS                               'Clear the screen.
INPUT "Enter a value: ", Value    'Prompt for input.
'Make the first two guesses.
X1 = 0#: X2 = Value
'Loop until the difference between guesses is
'less than the required precision.
DO UNTIL ABS(X1 - X2) < Precision
    X = (X1 + X2) / 2#
    ' Adjust the guesses.
    IF X * X * X - Value < 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.99999997206032