O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required