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.
SGN Function Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example calculates and prints the solution for the input quadratic
'(or second-degree) equation. The program uses the sign of the discriminant
'returned by the SGN function to determine how to calculate the solution.
 
CONST NoRealSoln = -1, OneSoln = 0, TwoSolns = 1
'Input coefficients of quadratic equation:
'ax^2 + bx + c = 0.
INPUT ; "a = ", A
INPUT ; ",  b = ", B
INPUT ",  c = ", C
Discriminant = B ^ 2 - 4 * A * C
SELECT CASE SGN(Discriminant)
   CASE NoRealSoln
      PRINT "This equation has no real-number solutions."
   CASE OneSoln
      PRINT "This equation has one solution: ";
      PRINT -B / (2 * A)
   CASE TwoSolns
      PRINT "This equation has two solutions: ";
      PRINT (-B + SQR(Discriminant)) / (2 * A); " and ";
      PRINT (-B - SQR(Discriminant)) / (2 * A)
END SELECT
 
'Sample Output
'
'a = 3,  b = -4,  c = 1
'This equation has two solutions:  1  and  .3333333