'===========================================================================
' Subject: PYTHAGOREAN THEOREM DEMO           Date: 05-26-96 (00:24)       
'  Author: Darryl Schneider                   Code: QB, QBasic, PDS        
'  Origin: fish2@datanet.ab.ca              Packet: ALGOR.ABC
'===========================================================================
'This is a little interactive educational program that
'explains how to find the hypotenuse of a right-angle
'triangle using the Pythagorean Theorem.
'
'Written by Darryl Schneider
'fish2@datanet.ab.ca
'The QBasic Zone
'http://www.geocities.com/SiliconValley/4244/qbasic.html
'
START:
CLS
DEFSTR E-F                              'declare all of the
DEFSNG A-D, G-Z                         'variables
SCREEN 12
PRINT ""
PRINT "              The Pythagorean Theorem"
PRINT ""
FOR D = 1 TO 50                         'draw the line
    PRINT CHR$(196);
NEXT D
PRINT ""
PRINT ""
LINE (100, 80)-(100, 200), 1            'draw and paint the triangle
LINE (100, 200)-(300, 200), 1
LINE (300, 200)-(100, 80), 1
PAINT (150, 120), 2, 1
LOCATE 7, 40: PRINT "a = altitude"      'print the legend
LOCATE 8, 40: PRINT "b = base"
LOCATE 9, 40: PRINT "h = hypotenuse"
LOCATE 9, 11: PRINT "a"
LOCATE 8, 27: PRINT "h"
PRINT ""
PRINT ""
PRINT ""
PRINT ""
PRINT ""
PRINT "                       b"
PRINT ""
PRINT ""
PRINT "       In order to understand the Pythagorean Theorem, let's"
PRINT "       do a little interactive demonstration to find the"
PRINT "       hypotenuse of a triangle."
PRINT ""
PRINT "       Press any key to begin....."
PRINT "       [Type 'Q' to quit]"
ATRIES = 0
BTRIES = 0
HTRIES = 0
DO
F = UCASE$(INKEY$)                  'asks for a one-character response
IF F = "Q" THEN END
LOOP UNTIL F <> ""

FINDH:
CLS
PRINT ""
PRINT "       Finding the hypotenuse of a triangle"
PRINT ""
FOR D = 1 TO 50                           'draw the line
     PRINT CHR$(196);
NEXT D
PRINT ""
PRINT ""
LINE (100, 80)-(100, 200), 1              'draw the triangle
LINE (100, 200)-(300, 200), 1
LINE (300, 200)-(100, 80), 1
PAINT (150, 120), 2, 1
LOCATE 7, 40: PRINT "a = altitude = "; A  'print the legend with values
LOCATE 8, 40: PRINT "b = base = "; B
LOCATE 9, 40: PRINT "h = hypotenuse = ?"
LOCATE 9, 5: PRINT A
LOCATE 8, 27: PRINT "h"
PRINT ""
PRINT ""
PRINT ""
PRINT ""
PRINT ""
PRINT "                       "; B
PRINT ""
PRINT ""
IF ATRIES = 0 THEN
          INPUT "What is the altitude"; A      'asks for altitude
          ATRIES = ATRIES + 1                  'of the triangle
          GOSUB FINDH
END IF
IF BTRIES = 0 THEN
          INPUT "What is the base"; B          'asks for base
          BTRIES = BTRIES + 1                  'of the triangle
          GOSUB FINDH
END IF
IF ATRIES = 1 AND BTRIES = 1 THEN GOSUB FINDHA     'altitude and
                                                   'base values have
                                                   'been given so we
                                                   'can now proceed
FINDHA:
PLAY "O3L20P1P1"
PRINT ""
PRINT " Now we can calculate the length of the hypotenuse:"
PRINT ""
LOCATE 20, 1: PRINT " aý + bý"; : LOCATE 20, 25: PRINT " = hý           'first write down the formula"
PLAY "O3L20P1P1"
LOCATE 21, 1: PRINT ""; A; "ý + "; B; "ý": LOCATE 21, 25: PRINT " = hý           'substitute a and b with numbers"
PLAY "O3L20P1P1"
G = A * A
H = B * B
LOCATE 22, 1: PRINT ""; G; " + "; H; : LOCATE 22, 25: PRINT " = hý           'find the product of each square"
PLAY "O3L20P1P1"
LOCATE 23, 1: PRINT ""; G + H; : LOCATE 23, 25: PRINT " = hý           'add the products of the squares"
LOCATE 24, 25: PRINT "                 together "
PLAY "O3L20P1P1"
LOCATE 25, 1: PRINT " û"; G + H; : LOCATE 25, 25: PRINT " = h            'the square root of the sum will equal"
LOCATE 26, 25: PRINT "                 the hypotenuse"
H = SQR(G + H)
PLAY "O3L20P1P1"
LOCATE 27, 1: PRINT ""; H; : LOCATE 27, 25: PRINT " = h            'the answer for the hypotenuse"
PLAY "o3l20p1p1"

CLS
PRINT ""
PRINT "    End of the Interactive Demonstration of the Pythagorean Theorem"
PRINT ""
FOR D = 1 TO 70
    PRINT CHR$(196);                         'draw the line
NEXT D
LINE (100, 80)-(100, 200), 1                 'draw the triangle
LINE (100, 200)-(300, 200), 1
LINE (300, 200)-(100, 80), 1
PAINT (150, 120), 2, 1
LOCATE 7, 40: PRINT "a = altitude = "; A     'print legend with all
LOCATE 8, 40: PRINT "b = base = "; B         'values
LOCATE 9, 40: PRINT "h = hypotenuse = "; H
LOCATE 9, 5: PRINT A
LOCATE 8, 27: PRINT H
PRINT ""
PRINT ""
PRINT ""
PRINT ""
PRINT ""
PRINT "                       "; B
PRINT ""
PRINT "       Type 'S' to start the program again or any other key to quit....."
'above is another one-character response prompt
DO
E = UCASE$(INKEY$)
IF E = "S" THEN GOSUB START
LOOP UNTIL E <> ""
IF NOT E = "S" THEN END
