17.2 Return Values
Consider again the two components of the program. It would be desirable, in the spirit of encapsulating functionality, to modify the program so that the main program alone handles interacting with the user and initiating the calculation, while the fac subroutine actually performs the calculation. The main goal of this approach is to allow the fac function to be called in other parts of the program to calculate another factorial. It should be possible to use the calculation result for further operations—for example, screen outputs or additional calculations. For this purpose, it’s essential that fac deals exclusively with the calculation. Having fac output the result of the calculation itself doesn’t fit into this concept. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access