A builder is building some simple houses in a neighborhood. They all have rectangular footprints and ordinary roofs running the length of the house. But just to add some character to the neighborhood, the builder is putting the roof beans a bit off center, rather than right over the center as you would expect. The task is to compute the roof area, given the dimensions.
Here is an elevation view of the end of a typical house:
Let Length be the length of the house (not shown, because we are looking at the end). Here is what we have to do to find the roof area:
The interesting part of the computation is to find the lengths of the two diagonal lines. Each length is the hypotenuse of a right triangle. Both triangles have the same height, namely Height. The bases of the triangles may be different; they are Offset and (Width - Offset). To get the length of a hypotenuse, we must use the Pythagorean Theorem: the square of the hypotenuse is equal to the sum of the squares of the sides. Because the hypotenuse calculation has to be done twice, we will use a function, so that we only have to write that part of the program once.
Now start the simulator, select Function Example B, and try it with several different sets of dimensions. Pay careful attention to what happens to the variables when the Diag function is called, and when the return statement is executed!