'=========================================================================== ' Subject: METRIC CONVERTER Date: Unknown Date ' Author: Unknown Author(s) Code: QB, QBasic, PDS ' Keys: METRIC,CONVERTER Packet: ALGOR.ABC '=========================================================================== DECLARE SUB Pause (a!) DECLARE SUB Frame (left%, Right%, top%, bottom%) DECLARE SUB Stars (co!, qwe$) DECLARE SUB Chart (starter, stoper, inc, number) DECLARE SUB CtoI () DECLARE SUB KtoF () DECLARE SUB FtoK () DECLARE SUB KtoC () DECLARE SUB CtoK () DECLARE SUB KtoP () DECLARE SUB PtoK () DECLARE SUB FtoC () DECLARE SUB CtoF () DECLARE SUB ItoC () DECLARE FUNCTION CM! (s!) DECLARE FUNCTION In! (a!) DECLARE FUNCTION CelK! (u!) DECLARE FUNCTION KelC! (l!) DECLARE FUNCTION KelF! (i!) DECLARE FUNCTION FahrK! (r!) DECLARE FUNCTION Kg! (o!) DECLARE FUNCTION Lbs! (n!) DECLARE FUNCTION Fahr! (a!) DECLARE FUNCTION Celsius! (s!) COMMON SHARED rou COLOR 13 BEEP ON KEY(31) GOSUB F12 KEY(31) ON CLS WIDTH 80, 50 r% = 5 c% = 37 Frame 23, 56, 1, 5 COLOR 10 LOCATE 2, 24 PRINT "Welcome to the metric converter:" COLOR 15 LOCATE 3, 36 PRINT "Convert" COLOR 10 LOCATE 4, 31 DO rou = 0 PRINT "Any key to continue" DO LOOP UNTIL INKEY$ <> "" CLS COLOR 12 LOCATE r% - 1, c% PRINT "M E N U" COLOR 13 Frame 27, 53, r% + 1, 28 LOCATE r% + 2, c% - 9 COLOR 14 PRINT "1"; COLOR 9 PRINT ". Fahrenheit to Celsius" LOCATE r% + 4, c% - 9 COLOR 14 PRINT "2"; COLOR 9 PRINT ". Celsius to Fahrenheit" LOCATE r% + 6, c% - 9 COLOR 14 PRINT "3"; COLOR 9 PRINT ". Inches to Centimeters" LOCATE r% + 8, c% - 9 COLOR 14 PRINT "4"; COLOR 9 PRINT ". Centimeters to Inches" LOCATE r% + 10, c% - 9 COLOR 14 PRINT "5"; COLOR 9 PRINT ". Kilogram to Pounds" LOCATE r% + 12, c% - 9 COLOR 14 PRINT "6"; COLOR 9 PRINT ". Pounds to Kilograms" LOCATE r% + 14, c% - 9 COLOR 14 PRINT "7"; COLOR 9 PRINT ". Kelvien to Celsius" LOCATE r% + 16, c% - 9 COLOR 14 PRINT "8"; COLOR 9 PRINT ". Celsius to Kelvien" LOCATE r% + 18, c% - 9 COLOR 14 PRINT "9"; COLOR 9 PRINT ". Kelvien to Fahrenheit" LOCATE r% + 20, c% - 9 COLOR 14 PRINT "0"; COLOR 9 PRINT ". Fahrenheit to Kelvien" LOCATE r% + 22, c% - 9 COLOR 14 PRINT "X"; COLOR 9 PRINT ". Exit" COLOR 11 LOCATE 49, 26 PRINT "[Esc] and [F12] also exit." LOCATE r% + 25, c% - 10 PRINT "Please enter your selection "; COLOR 27 PRINT "_" COLOR 11 CALL Stars(2, qwe$) a$ = qwe$ IF a$ = CHR$(27) THEN EXIT DO COLOR 15 LOCATE r% + 25, c% + 19 PRINT a$ COLOR 13 SLEEP 1 w$ = UCASE$(a$) SELECT CASE w$ CASE "1" rou = 1 FtoC CASE "2" rou = 2 CtoF CASE "3" rou = 3 ItoC CASE "4" rou = 4 CtoI CASE "5" rou = 5 KtoP CASE "6" rou = 6 PtoK CASE "7" rou = 7 KtoC CASE "8" rou = 8 CtoK CASE "9" rou = 9 KtoF CASE "0" rou = 0 FtoK CASE "X" GOSUB F12: CASE ELSE LOCATE , 22 PRINT "Please press only a key from [1 to 7]" LOCATE , 31 END SELECT COLOR 13 BEEP LOOP F12: BEEP COLOR 11 FOR q = 29 TO 37 LOCATE q PRINT SPACE$(80) NEXT q Frame 28, 52, 30, 36 COLOR 10 LOCATE 32, 31 PRINT "Thank-you for using" COLOR 15 LOCATE 34, 37 PRINT "Convert" COLOR 7 END F9: COLOR 10 Pause 0 COLOR 11 RETURN FUNCTION CelK (o) CelK = o - 273.15 END FUNCTION FUNCTION Celsius (m) Celsius = 5 / 9 * (m - 32) END FUNCTION SUB Chart (st, en, inc, r) ON KEY(9) GOSUB F9: KEY(9) ON CLS COLOR 12 Frame 23, 56, 1, 6 COLOR 10 LOCATE 2, 33 PRINT "Converter Chart" PRINT LOCATE , 24 COLOR 13 PRINT "Press [F9] once to pause listing" LOCATE , 27 PRINT "Then hit any key to resume" PRINT PRINT COLOR 15 SELECT CASE r CASE 1 PRINT " Fahrenheit", " Celsius" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## øF ==IS== ######.## øC"; q; Celsius(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 2 PRINT " Celsius", " Fahrenheit" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## øC ==IS== ######.## øF"; q; Fahr(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 3 PRINT " Inches", " Centimeters" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## & ==IS== ######.## cm"; q; CHR$(34); CM(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 4 PRINT " Centimeters", " Inches" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## cm ==IS== ######.## &"; q; In(q); CHR$(34) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 5 PRINT " Kilograms", " Pounds" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## kg ==IS== ######.## lbs"; q; Lbs(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 6 PRINT " Pounds", " Kilograms" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## lbs ==IS== ######.## kg"; q; Kg(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 7 PRINT " Kelvien", " Celsius" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## K ==IS== ######.## øC"; q; CelK(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 8 PRINT " Celsius", " Kelvien" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## øC ==IS== ######.## K"; q; KelC(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 9 PRINT " Kelvien", " Fahrenheit" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## K ==IS== ######.## øF"; q; FahrK(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT CASE 0 PRINT " Fahrenheit", " Kelvien" PRINT VIEW PRINT 10 TO 50 COLOR 11 FOR q = st TO en STEP inc PRINT USING "######.## øF ==IS== ######.## K"; q; KelF(q) ' WAIT &H20, 1 ' WAIT &H20, 1 NEXT q PRINT END SELECT Pause 2 VIEW PRINT CLS KEY(9) OFF END SUB FUNCTION CM (i) CM = i * 2.54 END FUNCTION SUB CtoF WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of temperatures" PRINT COLOR 11 INPUT "Enter Celsius (øC) temperature:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting temperature (øC):->", st PRINT INPUT "Enter Ending temperature (øC):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending temperature MUST be greater than Starting temperature!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF w = VAL(a$) PRINT USING "That temperature in Fahrenheit is_->######.## øF"; Fahr(w) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB SUB CtoI WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of lengths" PRINT COLOR 11 INPUT "Enter length in Centimeters:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting length (cm):->", st PRINT INPUT "Enter Ending length (cm):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending length MUST be greater than Starting length!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF q = VAL(a$) PRINT USING "That length in Inches is_->######.## &"; In(q); CHR$(34) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB SUB CtoK WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of temperatures" PRINT COLOR 11 INPUT "Enter Celsius (øC) temperature:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting temperature (øC):->", st PRINT INPUT "Enter Ending temperature (øC):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending temperature MUST be greater than Starting temperature!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF s = VAL(a$) PRINT USING "That temperature in Kelvien is_->######.## K"; KelC(s) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB FUNCTION Fahr (c) Fahr = (c * 9 / 5) + 32 END FUNCTION FUNCTION FahrK (k) FahrK = ((k - 273.15) * 9 / 5) + 32 END FUNCTION SUB Frame (left%, Right%, top%, bottom%) STATIC horiz% = Right% - left% - 1 hline$ = STRING$(horiz%, 205) FOR vert% = top% + 1 TO bottom% - 1 LOCATE vert%, left% PRINT CHR$(186); SPC(horiz%); CHR$(186) NEXT vert% LOCATE bottom%, left% PRINT CHR$(200); LOCATE bottom%, left% + 1 PRINT hline$; LOCATE bottom%, Right% PRINT CHR$(188); LOCATE top%, left% PRINT CHR$(201); LOCATE top%, left% + 1 PRINT hline$ LOCATE top%, Right% PRINT CHR$(187); END SUB SUB FtoC WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of temperatures" PRINT COLOR 11 INPUT "Enter Fahrenheit temperature:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting temperature (øF):->", st PRINT INPUT "Enter Ending temperature (øF):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending temperature MUST be greater than Starting temperature!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF j = VAL(a$) PRINT USING "That temperature in Celsius is_->######.## øC"; Celsius(j) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB SUB FtoK WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of temperatures" PRINT COLOR 11 INPUT "Enter Fahrenheit (øF) temperature:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting temperature (øF):->", st PRINT INPUT "Enter Ending temperature (øF):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending temperature MUST be greater than Starting temperature!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF h = VAL(a$) PRINT USING "That temperature in Kelvien is_->######.## K"; KelF(h) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB FUNCTION In (c) In = c / 2.54 END FUNCTION SUB ItoC WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of lengths" PRINT COLOR 11 INPUT "Enter length in Inches:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting length (Inches):->", st PRINT INPUT "Enter Ending length (Inches):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending length MUST be greater than Starting length!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF i = VAL(a$) PRINT USING "That length in Centimeters is_->######.## &"; CM(i) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB FUNCTION KelC (c) KelC = c + 273.15 END FUNCTION FUNCTION KelF (f) KelF = (5 / 9 * (f - 32)) + 273.15 END FUNCTION FUNCTION Kg (p) Kg = p / 2.2 END FUNCTION SUB KtoC WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of temperatures" PRINT COLOR 11 INPUT "Enter Kelvien (K) temperature:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting temperature (K):->", st PRINT INPUT "Enter Ending temperature (K):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending temperature MUST be greater than Starting temperature!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF k = VAL(a$) PRINT USING "That temperature in Celsius is_->######.## øC"; CelK(k) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB SUB KtoF WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of temperatures" PRINT COLOR 11 INPUT "Enter Kelvien (K) temperature:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting temperature (K):->", st PRINT INPUT "Enter Ending temperature (K):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending temperature MUST be greater than Starting temperature!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF k = VAL(a$) PRINT USING "That temperature in Fahrenheit is_->######.## øF"; FahrK(k) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB SUB KtoP WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of weights" PRINT COLOR 11 INPUT "Enter weight in Kilograms:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting weight (kg):->", st PRINT INPUT "Enter Ending weight (kg):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending weight MUST be greater than Starting weight!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF k = VAL(a$) PRINT USING "That weight in Pounds is_->######.## lbs"; Lbs(k) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB FUNCTION Lbs (k) Lbs = 2.2 * k END FUNCTION SUB Pause (a) PRINT IF a = 0 THEN LOCATE , 27 PRINT "Press any key to continue." PRINT DO LOOP WHILE INKEY$ = "" END SUB SUB PtoK WHILE INKEY$ <> "" WEND CLS DO DO COLOR 13 PRINT "Type 'end' to exit" PRINT "Type 'chart' to make a chart of weights" PRINT COLOR 11 INPUT "Enter weight in Pounds:->", a$ IF UCASE$(a$) = "END" THEN PRINT EXIT DO END IF IF UCASE$(a$) = "CHART" THEN PRINT PRINT COLOR 10 INPUT "Enter Starting weight (lbs):->", st PRINT INPUT "Enter Ending weight (lbs):->", en PRINT INPUT "Increment:->", inc PRINT IF en < st THEN PRINT "Ending weight MUST be greater than Starting weight!" PRINT SLEEP 3 COLOR 11 EXIT DO END IF COLOR 11 roun = rou Chart st, en, inc, roun PRINT EXIT DO END IF p = VAL(a$) PRINT USING "That weight in Kilograms is_->######.## kg"; Kg(p) COLOR 13 PRINT LOOP LOOP WHILE UCASE$(a$) <> "END" END SUB SUB Stars (co, qwe$) COLOR co a$ = "* * * * * * * * * * * * * * * * * " WHILE INKEY$ <> "" WEND DO FOR a% = 1 TO 5 LOCATE 1, 1 PRINT MID$(a$, a%, 80); LOCATE 33, 1 PRINT MID$(a$, 6 - a%, 80); FOR b% = 2 TO 31 c% = (a% + b%) MOD 5 IF c% = 1 THEN LOCATE b%, 80 PRINT "*"; LOCATE 33 - b%, 1 PRINT "*"; ELSE LOCATE b%, 80 PRINT " "; LOCATE 33 - b%, 1 PRINT " "; END IF NEXT b% NEXT a% qwe$ = INKEY$ LOOP WHILE qwe$ = "" END SUB