6.7. Functions

In the last section I mentioned “all the things functions are good for.” About this time, you might be wondering what exactly those things are. Here are some of the reasons functions are useful:

For example, instead of writing the 53 lines of code below…

..you would reduce it to the 21 lines of code below, making it easier to read, debug, and use the function many times with rewriting it each time.

Create a function called absoluteValue, which returns the absolute value of a parameter num. Assume you do not have access to #include <cmath>.

You have attempted of activities on this page