previous | start | next

## Writing Functions (Hard Wired Values)

- The `future_value` function in `futval.cpp` is flawed because the starting amount of the investment and the number of years are hard-wired.
- Hard-wiring prevents reuse of functions:
  - Computing the balance after 20 years.
  - Computing the balance with a different interest rate.
- We avoid hard-wiring values into functions by passing them in as additional parameters.
- Functions are more valuable when they are reusable.

>     double future_value(double initial_balance, double p, int n)
>     {
>        double b = initial_balance * pow(1 + p / 100, n);
>        return b;
>     }

previous | start | next