Joseph D. Sloan
sloanjd @ wofford.edu
Code by imitation
Code by careful design—Carpet calculation example
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
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.
The inputs are length and width of the room and the cost of the carpet. Notice we have named two variable in the process.
The output is the totalCost of the carpet
Calculate the area of the room: area = length * width
Calculate the totalCost of the carpet: totalCost = area * cost