Question about PS1b (Intro to CS spring 2011):
1) What is the decrementing function here? I am confused
2) If balance was 1200 to start with, would newBalance be 1208 after the first loop?
If someone could walk through this problem in words using an example balance I would really appreciate it.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your **free** account and access **expert** answers to this

and **thousands** of other questions.

- anonymous

- chestercat

I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your **free** account and access **expert** answers to this

and **thousands** of other questions

- anonymous

What you're solving for here is "what monthly payment (in multiples of 10) do you need to pay off the balance within 12 months".
Here's an example run of the program:
Enter the outstanding balance on your credit card: 280
Enter the annual credit card interest rate as a decimal: .2
Month: 1 balance: 275.0 monthlyPayment: 10
Month: 2 balance: 269.0 monthlyPayment: 10
Month: 3 balance: 264.0 monthlyPayment: 10
Month: 4 balance: 258.0 monthlyPayment: 10
Month: 5 balance: 252.0 monthlyPayment: 10
Month: 6 balance: 247.0 monthlyPayment: 10
Month: 7 balance: 241.0 monthlyPayment: 10
Month: 8 balance: 235.0 monthlyPayment: 10
Month: 9 balance: 229.0 monthlyPayment: 10
Month: 10 balance: 222.0 monthlyPayment: 10
Month: 11 balance: 216.0 monthlyPayment: 10
Month: 12 balance: 210.0 monthlyPayment: 10
Month: 1 balance: 265.0 monthlyPayment: 20
Month: 2 balance: 249.0 monthlyPayment: 20
Month: 3 balance: 233.0 monthlyPayment: 20
Month: 4 balance: 217.0 monthlyPayment: 20
Month: 5 balance: 201.0 monthlyPayment: 20
Month: 6 balance: 184.0 monthlyPayment: 20
Month: 7 balance: 167.0 monthlyPayment: 20
Month: 8 balance: 150.0 monthlyPayment: 20
Month: 9 balance: 132.0 monthlyPayment: 20
Month: 10 balance: 115.0 monthlyPayment: 20
Month: 11 balance: 97.0 monthlyPayment: 20
Month: 12 balance: 78.0 monthlyPayment: 20
Month: 1 balance: 255.0 monthlyPayment: 30
Month: 2 balance: 229.0 monthlyPayment: 30
Month: 3 balance: 203.0 monthlyPayment: 30
Month: 4 balance: 176.0 monthlyPayment: 30
Month: 5 balance: 149.0 monthlyPayment: 30
Month: 6 balance: 122.0 monthlyPayment: 30
Month: 7 balance: 94.0 monthlyPayment: 30
Month: 8 balance: 65.0 monthlyPayment: 30
Month: 9 balance: 36.0 monthlyPayment: 30
Month: 10 balance: 7.0 monthlyPayment: 30
Month: 11 balance: -23.0 monthlyPayment: 30
RESULT
Monthly payment to pay off debt in 1 year: 30
Number of months needed: 11
Balance: -23.09
You'll notice it starts the monthly payment at 10. Then runs through all 12 months making a payment each month. After each payment, it checks to see if it's paid off.
Because it doesn't get paid off within a year at 10/month, it adds 10 (resulting in a monthly payment of 20) and runs through all 12 months again. Checking, of course, every month to see if it's paid in full.
It didn't get paid entirely at 20/month so it adds another 10 and runs through the loop to check 30/month ... when it gets to month 11 it determines that everything is paid!
At that point, it's solved ... for these input values, it takes 11 months at 30/month to pay it off in under a year.
An important note:
When you're subtracting the current month's payment from the total each month, remember to ALSO add in the interest for that month at the same time.

- anonymous

Roaming Blue,
That is exactly what I was looking for. I was having trouble seeing the sequence of the loops. Now I understand the answer to the problem! Thank you very much for your detailed response.
Regards,
Tyler

- lopus

http://dpaste.com/788942/

Looking for something else?

Not the answer you are looking for? Search for more explanations.

## More answers

- anonymous

@tcc8m Anytime mate, happy coding.

Looking for something else?

Not the answer you are looking for? Search for more explanations.