Example 56: Calculate Interest
Explore how to create and apply macro definitions in C for calculating simple interest and total amount. This lesson helps you understand using preprocessor macros to write clean and maintainable financial calculations in your programs.
We'll cover the following...
Problem
Write macro definitions with arguments for the calculation of simple interest and total amount. Store these macro definitions in a file called interest.h.
Include this file in your program, and use the macro definitions for calculating simple interest and amount.
Solution
Given below is our recommended way to approach this problem.
Explanation
It is a simple program that calculates simple interest and the total amount after interest. Initially, we define the macro definitions for the following formulae:
- Simple interest
- Amount
The formula to calculate simple interest is:
...