/* REXX HERO Calculate the area of a triangle given the lengths of its sides. */ arg argline /* pro-forma quick-start */ address TSO arg parms "((" opts opts = Strip(opts,"T",")") parse var opts "TRACE" tv . parse value tv "N" with tv . rc = Trace("O"); rc = Trace(tv) "CLEAR" do forever say "Enter the three sides of a triangle (? for help):" "NEWSTACK" parse pull s1 s2 s3 . "DELSTACK" if s1 = "?" then do say "This routine implements Hero's formula for computing the area" say "of a triangle given only the lengths of its three sides. It " say "first computes the semi-perimeter, one half the sum of the " say "sides. Then it multiplies that semi-perimeter with the " say "differences between each side and the semi-perimeter. The " say "square root of that number is the area of the triangle. " say iterate end if s3 = "" then leave if Datatype( s1,'N' ) +, Datatype( s2,'N' ) +, Datatype( s3,'N' ) < 3 then do say "You entered" s1 s2 s3". I need three NUMBERS. Try again." "NEWSTACK"; pull; "DELSTACK" iterate end /* datatype */ sp = (s1 + s2 + s3) / 2 /* semi-perimeter */ inner = sp * (sp-s1) * (sp-s2) * (sp-s3) area = SQRT( inner ) say "A triangle with sides" s1 s2 s3 "has an area of" area "NEWSTACK"; pull; "CLEAR"; "DELSTACK" end /* forever */ "CLEAR" exit /*@ HERO */