Section 19.7 Functions Calling Functions - 3
Here is the final version of our program, being used to test a new triangle. Use the Codelens view to run the program. As you watch it run, here are some things to pay attention to:
-
The program starts running lines of code at the main part (non-indented code)
-
The main part calls
triangle_area -
triangle_areacallsdistancethree times. After each timedistanceruns, it returns a value that gets used bytriangle_areato set a, b, or c -
What
distancecalls x1, x2, y1, and y2 does not always match the names used for those values intriangle_area. For example, when we calldistance(x2, y2, x3, y3)intriangle_area, distance will be given the value thattriangle_areais calling x2 as its first parameter.distancecalls its first parameter x1.This is a little confusing if we try to think of something like x1 as some fixed value that all functions agree on. But that is not how variables work. If multiple functions or procedures have a parameter or variable named x1, each one is potentially talking about a different piece of information.
When the perimeter is set in
triangle_area, use the value to answer the question below the code sample.
You have attempted of activities on this page.
