! Practice Program 6-3

! Rewrite Practice Program 6-1 with an error-handling block.

 

INPUT prompt "Value of A? ": A

INPUT prompt "Value of B? ": B

INPUT prompt "Value of C? ": C

WHEN ERROR IN

LET X1 = (-B + Sqr(B*B - 4*A*C)) / (2*A)

LET X2 = (-B - Sqr(B*B - 4*A*C)) / (2*A)

PRINT "The roots are "; X1; "and "; X2

USE

PRINT "The roots are complex."

END WHEN

PRINT extype,extext$

END

Result of program with A,B,C=1,2,3:

Value of A? 1

Value of B? 2

Value of C? 3

The roots are complex.

3005 SQR of negative number.