previous | start

## Preconditions

- To use `assert()` you must `#include<cassert>`.
- `assert()` is really a macro - a special instruction to the compiler that inserts complex code into the program.

  >     double future_value(double initial_balance, double p, int n)
  >     {
  >        assert(p >= 0);
  >        assert(n >= 0);

  >        return initial_balance * pow(1 + p / 100, n);
  >     }

- As a programmer, you must fully document any preconditions that the function must meet. That is, the legal values for function input.

  >     /**
  >        Computes the value of an investment with compound interest.
  >        @param initial_balance the initial value of the investment
  >        @param p the interest rate in percent; must be >= 0
  >        @param n the number of periods the investment is held; must be >= 0
  >        @return the balance after n periods
  >     */

- If a function call does not satisfy the preconditions, the function is free to do anything.
  - Function causes the program to terminate.
  - Return a "safe" default value.

previous | start