5.1 Introduction

This chapter continues our presentation of structured-programming theory and principles by introducing all but one of C++’s remaining control statements. We demonstrate C++’s for, dowhile and switch statements. Through examples using while and for, we explore the essentials of counter-controlled iteration. We also use compound-interest calculations to begin investigating the issues of processing monetary amounts. First, we discuss the representational errors associated with floating-point types. Then, we develop a new DollarAmount class that uses very large integers to precisely represent monetary amounts. As you’ll see, the class uses only precise integer arithmetic, thus eliminating the kind of representational errors associated ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.