Thanh Hoang

Greenhorn

Posts: 6

posted 1 year ago

Do you mean the do/while loop? Right now it loops forever; probably not a good idea. How about asking if they user wants to calculate another loan and in the while, test for yes/no?

What are you stuck on? Please TellTheDetails (that's a link).

Do you mean the do/while loop? Right now it loops forever; probably not a good idea. How about asking if they user wants to calculate another loan and in the while, test for yes/no?

What are you stuck on? Please TellTheDetails (that's a link).

All things are lawful, but not all things are profitable.

Thanh Hoang

Greenhorn

Posts: 6

posted 1 year ago

Yes. I want my program determine how many months it will take to pay off that loan, what the final payment amount will be, and how much interest was paid over that time. If the monthly payment amount isn't high enough to pay off more than one month's interest, my program should notify the user what the minimum monthly payment is

posted 1 year ago

So you weren't given these formulae? Does this help?

https://en.wikipedia.org/wiki/Amortization_calculator

https://en.wikipedia.org/wiki/Amortization_calculator

All things are lawful, but not all things are profitable.

Thanh Hoang

Greenhorn

Posts: 6

posted 1 year ago

I'm sorry but no, It doesn't help anyway. I'm stuck on the formular to calculate the interest month and count how many month did we use to paid off.

Like this example

How much do you want to borrow? $1000

What is the annual interest rate expressed as a percent? 18

What is the monthly payment amount? $50

Your debt will be paid off after 24 months, with a final payment of just $47.83

The total amount of interest you will pay during that time is $197.83

Like this example

How much do you want to borrow? $1000

What is the annual interest rate expressed as a percent? 18

What is the monthly payment amount? $50

Your debt will be paid off after 24 months, with a final payment of just $47.83

The total amount of interest you will pay during that time is $197.83

posted 1 year ago

Does this help?

https://en.wikipedia.org/wiki/Amortization_schedule#Outstanding_loan_balance_calculation

(I'm just Googling this stuff. The keyword is "amortization". So this link was found with amortization number of payments)

https://en.wikipedia.org/wiki/Amortization_schedule#Outstanding_loan_balance_calculation

(I'm just Googling this stuff. The keyword is "amortization". So this link was found with amortization number of payments)

All things are lawful, but not all things are profitable.

Thanh Hoang

Greenhorn

Posts: 6

posted 1 year ago

Please

*surround*your code with code tags. Please read this.All things are lawful, but not all things are profitable.

posted 1 year ago

I believe I've given you the information you need. If you have a

I still don't understand about the interest month. If you can give me a hint or a code...

I believe I've given you the information you need. If you have a

*specific*question, I'll be glad to answer it. If you're looking for me or anyone to supply you with the code, that's not going to happen. CodeRanch is not a code mill.

All things are lawful, but not all things are profitable.

Piet Souris

Master Rancher

Posts: 2044

75

posted 1 year ago

In this reply: click here

I tried to give a hopefully comprehensible explanation regarding some elementary financial maths formulae.

Let the monthly payment be P, and let the monthly interest be rr (per unit loan, for instance 0.005). Since we do not want the unamortized part of the loan to increase each month, we need to make P at least equal to the monthly interet payment. So we get, the loan being L:

1) P >= rr * L (if P = rr * L, we call this a perpetuity, a never ending loan)

2) let the unamortized Loan at the end of month m, right after the monthly payment, be UL(m). We get this recursion relation (can you think of why?)

UL(m + 1) = UL(m) * (1 + rr) - P

3) and of course, UL(0) = L

Now, at the end of each month m, just before the payment P, the UL is equal to UL(m) * (1 + rr). To determine both the duration and the final payment, we get this while loop:

Note: I typed this code straight from the keyboard, and so is untested.

HTH,

Piet

edit: reversed the lines of interestTotl and UL

I tried to give a hopefully comprehensible explanation regarding some elementary financial maths formulae.

Let the monthly payment be P, and let the monthly interest be rr (per unit loan, for instance 0.005). Since we do not want the unamortized part of the loan to increase each month, we need to make P at least equal to the monthly interet payment. So we get, the loan being L:

1) P >= rr * L (if P = rr * L, we call this a perpetuity, a never ending loan)

2) let the unamortized Loan at the end of month m, right after the monthly payment, be UL(m). We get this recursion relation (can you think of why?)

UL(m + 1) = UL(m) * (1 + rr) - P

3) and of course, UL(0) = L

Now, at the end of each month m, just before the payment P, the UL is equal to UL(m) * (1 + rr). To determine both the duration and the final payment, we get this while loop:

Note: I typed this code straight from the keyboard, and so is untested.

HTH,

Piet

edit: reversed the lines of interestTotl and UL

Thanh Hoang

Greenhorn

Posts: 6

Piet Souris

Master Rancher

Posts: 2044

75

posted 1 year ago

Not when I run my code.

Well, test it, but what 'number on the new balance' are you referrng to?

Anyway, I ran your latest code, together with my code. This is what I got:

So there is still some work to be done. See if you can spot why you got an infinite run time with my code, it means giving the code some thorough testing!

Thanh Hoang wrote:It will run to infinity

Not when I run my code.

Thanh Hoang wrote:Can we count the number on the new balance as the number of month?

Well, test it, but what 'number on the new balance' are you referrng to?

Anyway, I ran your latest code, together with my code. This is what I got:

`** Welcome to the Consumer Loan Calculator **`

How much do you want to borrow? $100

What is the annual interst rate expressed as a percent? 12

What is the monthly payment amount? $4

Your dept will be paid off after months97.0

with a final payment of just $101.0

The total amount of interest you

will pay during that time is $1.0

************************************

loan is amortized after 29 months.

with a final payment of 3,65

total interest paid = 15,65

*******************************************

How much do you want to borrow? $100

What is the annual interst rate expressed as a percent? 12

What is the monthly payment amount? $4

Your dept will be paid off after months97.0

with a final payment of just $101.0

The total amount of interest you

will pay during that time is $1.0

************************************

loan is amortized after 29 months.

with a final payment of 3,65

total interest paid = 15,65

*******************************************

So there is still some work to be done. See if you can spot why you got an infinite run time with my code, it means giving the code some thorough testing!

Campbell Ritchie

Marshal

Posts: 56536

172

Consider Paul's rocket mass heater. |