CH 3 SUBPROGRAMS
Subprograms: Functions and Procedures
PROCEDURES (a.k.a. "void functions" in C)
To simplify the organization of a solution via decompostion
Used for more complicated tasks or when multiple values result (Ch 6).
No return value.
May do input/output with user.
Invoked like a statement.
Fig 3.14 - Draw Stick Figure
FUNCTIONS (a.k.a. "value returning functions" in C)
double CalculateDistance(double speed, double time)
1. To eliminate redundant code. (Hypotenuse
2. To facilitate code reuse
Used for simple, single purpose tasks that compute a single result.
Invoked on the right hand side of an assignment statement,
in a print statement,
or as part of an expression.
In general, functions should not perform input/output with user.
Fig 3.24 - Scale Function
Prediction Exercise Ch3_1.c