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.

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

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 1 of 6 activities on this page