Future Value Code in Text
Changing number of years
Printing each year
Labeling Output
Adding yearly deposits
Testing the Code!!!
(Change interest periods)
Program Design
Code by imitation
Code by careful design—Carpet calculation example
1. Understand the problem
We want to calculate the cost of carpet for a room. We'll need the cost of the carpet and the size of the room and we'll get the total cost
2. Work once by hand (if feasible)
Let the room be 10 feet by 12 feet and the (lavish) carpet $10 per square foot. The size of the room is 10 x 12 or 120 square feet. The cost of the carpet is 120 x $10 or $1200.
3. Identify inputs
The inputs are length and width of the room and the cost of the carpet. Notice we have named two variable in the process.
4. Identify outputs
The output is the totalCost of the carpet
5. Identify steps in calculation
Calculate the area of the room: area = length * width
Calculate the totalCost of the carpet: totalCost = area * cost