Write a program that helps the user to consider a range of interest rates for a mortgage over 20, 25, and 30 years. Prompt the user to enter the amount of the loan and a minimum and maximum interest rate (in whole percentages). Then write a text file containing a table of the form:

Loan Amount: $50,000.00

Rate Duration
(years) Monthly
Payment Total

10.00 20 ________
10.00 25 ________ ________
10.00 30 ________ ________
10.25 35 ________ ________
The output file produced should contain payment information on a particular loan amount for interest rates from the minimum rate to the maximum rate in increments of 0.25%. The loan durations should be 20, 25, and 30 years. Output the monthly payment and total payment values rounded to two decimal places. You may neglect the fact that because the monthly payment must be rounded, the final payment will be slightly different. The formula for calculating monthly payment is

P = principal (the amount you borrow)
i = monthly interest rate (1/12 of the annual rate)
n = total number of payments

Welcome to the fourm, Huzaifah! ;)

The way programming forums work is that you FIRST need to show what you have done, and then ask specific questions about any problems you have found.

We help people with programming problems, but they have to show they're actively working on it. Otherwise, we become a free homework service, and that simply isn't what we want to be.

In your problem, it appears that a while(money is owed) outer loop, and a nested inner for loop from 0 to 11, calculating each month's data, would be appropriate. To handle the different interest rates, I'm thinking another nested loop, outside both of the above mentioned loops, would be needed. Basically, re-calculating everything again, using a different interest loop, see?

I would avoid the idea of somehow consolidating all the interest rate calculations, so they are done within the same loops or function calls. That gets very involved and much harder to debug.

Keep it simple, and don't worry about the speed. These kinds of programs run in the blink of an eye almost.

Start with getting one month working right, then work on the year, then on the whole payment schedule for a single mortgage payback. Check it that it's accurate, and use functions and function calls to cut down on the repeated code.

Then work on getting the full range of interest payments for the loan, in the required steps, last thing.

Working one thing at a time like this, it goes much quicker than trying to do everything at once.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.