5.8. 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…

A function allows you to reduce it to the 21 lines of code below. The function makes it easier to read, debug, and use the function many times without 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