Reading
None.
In-class group activity: a financial simulation
Today you will break up into groups and write a program to do a
simple financial simulation. The program reads in a target
amount to save, an initial amount of a money, a monthly
contribution and an interest rate, and prints out how long (in
an integer number of years and months) it takes to save that
amount of money. Here are some example inputs and outputs. You
must conform to this input/output syntax, and that means getting
the "year" vs. "years" and "month" vs. "months" part right!
~/$ ./loancalc
target = $1000.00 initial = $490.00 monthly = $85.50 rate = 7.8%
After 6 months you will have saved $1034.22 dollars, which meets your target.
~/$ ./loancalc
target = $1000.00 initial = $0.00 monthly = $85.50 rate = 7.8%
After 1 year you will have saved $1070.4 dollars, which meets your target.
~/$ ./loancalc
target = $18000.00 initial = $490.00 monthly = $85.50 rate = 7.8%
After 10 years and 7 months you will have saved $18021.4 dollars, which meets your target.
~/$ ./loancalc
target = $18000.00 initial = $490.00 monthly = $85.50 rate = 3.2%
After 13 years and 6 months you will have saved $18096.6 dollars, which meets your target.
~/$ ./loancalc
target = $18000.00 initial = $1000.00 monthly = $85.50 rate = 3.2%
After 13 years you will have saved $18072.8 dollars, which meets your target.
~/$ ./loancalc
target = $18200 initial = $0 monthly = $85.50 rate = 3.2%
After 14 years and 1 month you will have saved $18273.5 dollars, which meets your target.
- Monthly contributions are made at the beginning of
each month.
- Interest is compounded at the end of each month, based on
the balance at the beginning of the month (which includes
that month's contribution).
- When quoted an annual interest rate r (as in this problem),
the monthly rate is r/12. Remember that
the rule for one step of interest is
interest = balance×rate.
So, for example, with $50 in the bank, a single compounding
step with rate 2% would give 50×0.02 → $1.00 of interest.
- You may assume the user always puts spaces around the = signs.
Problems
-
A volleyball scoring program.