# Advice on a coding lesson! Credit Card debt and Loops

As my students were learning about loops, I really wanted to add  tie-in to personal financial literacy.  My students are still very new to programming and this was their first experience with “for” loops. I am struggling with the right amount of structure for this task and would love your help reflecting on it.

Relevant standards:

7th grade Expressions and Equations: Multi-step ratio and proportion problems
CCSS.MATH.CONTENT.7.EE.B.3
Solve multi-step real-life and mathematical problems posed with positive and negative rational numbers in any form (whole numbers, fractions, and decimals), using tools strategically. Apply properties of operations to calculate with numbers in any form; convert between forms as appropriate; and assess the reasonableness of answers using mental computation and estimation strategies.

High School Functions: Exponential Growth
CCSS.MATH.CONTENT.HSF.LE.A.3
Observe using graphs and tables that a quantity increasing exponentially eventually exceeds a quantity increasing linearly, quadratically, or (more generally) as a polynomial function.

Computer Science Teachers Association: Middle School
Implement problem solutions using a programming language, including: looping behavior, conditional statements, logic, expressions, variables, and functions.

I gave the students this problem situation.

Fresh out of college, you need to buy furniture for your new apartment. You’re able to get a credit card with a 15% Annual Percentage Rate (APR). You immediately charge \$5000 to the credit card for your new accessories for the crib.

The minimum payment on the credit card is \$25, which you pay faithfully every month.
The credit card company charges you 1/12 of the APR every month on whatever money is left on the card.

Write a program that will calculate how much you have left to pay after 36 months.

From here, I have choices.

1) I can give students the pseudocode, and have them write the code.

```Use variables for:
amount of debt,
APR,
monthly payment,
number of months,```
```Repeat this loop for the number of months:
Subtract the monthly payment from the debt.
Add the fee to the debt (1/12 of the APR * the debt)

At the end, show how much debt is left.```

2) I can give them skeleton code to fill in.

```var debt = 5000;
var apr = 0.15;
var payment = 25;
var months = 36;```
```// complete
println( );```
```for(var i = 0;i<months; i+=1)
{
// add code and finish println statement

println( );
}```
```// complete
println( );```

3) I can have them enter the “canned” code and then modify it to answer the key questions.

```var debt = 5000;
var apr = 0.15;
var payment = 25;
var months = 36;

println("In the beginning you owed: \$" + debt);

for(var i = 0;i<months; i+=1)
{
println("At the start of month " + i + " you have \$" +debt + " in debt");
debt = debt - payment;
debt = debt + (apr / 12 * debt);

}

println("At the end you have \$" + debt + " in debt.");```

Here are the questions.
How much will you have to pay each month to pay off the credit card in 36 months?

Modify the program so it prints a message when the card is paid off.