Breaking the Example into Functions

The program is getting a bit long by now. Even with the use of exception handling to reduce the amount of error code, it is getting a little hard to follow. So you can split it into functions, each of which is a smaller and more understandable piece of largely self-contained code with a name that indicates its purpose. Listing 7.1 shows what the program looks like when you do this.

Listing 7.1. The Example as Functions
 1: #include <iostream> 2: 3: using namespace std; 4: 5: void Initialize(void) // No return value, no arguments 6: { 7: cin.exceptions(cin.failbit); 8: } 9: 10: float GetDividend(void) // Returns dividend, a float 11: { 12: float Dividend = 0; 13: 14: cout << "Dividend: "; 15: cin >> Dividend; ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION 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.