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

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

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