Getting started with functions
Welcome to the world of C++ functions. Functions are one of the fundamental building blocks of C++ programming. When I said earlier that you probably knew enough C++ to write a retro text adventure, after learning about functions, you definitely will!
Functions allow us to wrap reusable parts of our code and create well-organized programs. The rest of this chapter will walk you through the essentials of functions, from their basic syntax to more advanced concepts, providing you with a comprehensive foundation and ending on how functions and classes are part of the same topic. You will then be ready to finish this game in this chapter and the next and stride confidently on to Chapter 6, where we will finally tackle the topic of object-oriented programming.
What exactly are C++ functions? A function is a collection of variables, expressions, and control flow statements (loops and branches). In fact, any of the code we have learned about in the...