Computing Compound Interest
A simple savings account earns compound interest over time, based upon an annual interest rate (e.g., 1% or 9%) per year. The basic computations proceed as follows:
-
A monthly interest rate is computed:
monthly_rate = annual_rate_percent / 1200.0;
-
The monthly rate determines the interest the bank adds to the
account each month, according to the formula:
interest = monthly_rate * (old balance) new balance = (old balance) + interest
For example, at an annual rate of 8%, the monthly rate is 0.00666667. With a starting balance of $100, the computations proceed as follows for the first year:
Starting Monthly Ending
Month Balance Interest Balance
0 ------ ---- 100.00
1 100.00 0.67 100.67
2 100.67 0.67 101.34
3 101.34 0.68 102.01
4 102.01 0.68 102.69
5 102.69 0.68 103.38
6 103.38 0.69 104.07
7 104.07 0.69 104.76
8 104.76 0.70 105.46
9 105.46 0.70 106.16
10 106.16 0.71 106.87
11 106.87 0.71 107.58
12 107.58 0.72 108.30
This problem asks to you
-
write a procedure
compute_until_doublethat computes monthly balance until the amount in the account doubles from the initial balance. -
write a program that uses
compute_until_doublein several ways.
The following notes provide additional information regarding this work.
-
procedure
compute_until_double-
The procedure should have the following signature:
void compute_until_double(double initial_balance, double annual_rate, char print_option, int *months_to_double)-
initial_balancegives the initial balance, before any interest has accrued. -
annual_rategives the annual percentage interest rate -
print_optionspecifies one of three alternatives:-
'n': no printing is to be done by the procedure -
'm': the status of the account (i.e., month number, starting balance, interest for that month, and ending balance) is printed every month. -
'y': the status of the account (i.e., year number, starting balance, interest for that year, and ending balance) is printed every year (i.e., every 12 months).
-
-
-
months_to_doublerefers to an integer variable in the main program, and the number of months required for the account balance to double is stored in this variable when the procedure concludes. -
Processing in
compute_until_doublecontinues until the balance in the account doubles from its original value. -
Regardless of what printing option is
selected,
compute_until_doublemay have only one loop. Within the loop, theprint_optionshould be consulted to determine whether or not to print the account balance for that loop iteration.
-
The procedure should have the following signature:
-
The program should compute and print the following:
- An initial table should be printed, giving a monthly status report for an account that starts with $100 at an 8% annual percentage rate. (That is, the first part of this table should agree exactly with the sample table given above — although spaces on a line may be inserted or deleted.)
- A second table should be printed, giving an annual status report for an account that starts with $300 at a 2% annual percentage rate.
- Starting with $100.00 in an account, the program should print a table giving the number of months for the account to double with annual interest rates of 1%, 2%, 3%, ..., 9%.
Grading
In addition to the general grading guidelines for evaluation, the assignment is worth 25 points.
- [15 points] Procedure computeUntilDouble
- [6 points] Correctness of computations in the main loop
-
[2 points] Correct printing for the
'n'option -
[2 points] Correct printing for the
'm'option -
[2 points] Correct printing for the
'y'option -
[3 points] Correct storage of the months to double in the location referenced by
months_to_double - [6 points] Main program
- [2 points] Computation and printing of monthly table
- [2 points] Computation and printing of annual table
- [2 points] Computation and printing of months to double
-
Comments on Program Format, Comments, Readability, etc.
(Points not given, but points can be deducted.) -
[4 points] Testing
- Test Plan with a numbered listing of the circumstances that can reasonably arise in this problem
- Listing of test cases to be considered, with the expected outcome
- Listing of actual test runs
- Statement of why the program is correct
