Problem:
You have just purchased a stereo system that costs $1000 on the following credit plan: No down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used to pay the interest and whatever is left is used to pay part of the remaining debt. Hence, the first month you pay 1.5% of $1000 in interest. That is $15 in interest. So, the remaining $35 is deducted from your debt which leaves you with a debt of $965.00. The next month you pay interest of 1.5% of $965.00, which is $14.48. Hence, you can deduct $35.52 (which is $50 - $14.48) from the amount you owe.
Write a program that will tell you how many months it will take you to pay off the loan, as well as the total amount of interest paid over the life of the loan. Use a loop to calculate the amount of interest and the size of the debt after each month. Put out the monthly amount of interest paid and remaining debt. Use a variable to count the number of loop iterations and hence the number of months until the debt is zero. You may want to use other variables as well. The last payment may be less than $50 if the debt is small, but do not forget the interest. If you owe $50, then your monthly payment of $50 will not pay off your debt, although it will come close. One month's interest on $50 is only 75 cents.
Since you have done a good job on the task so far, I decided to put in the effort and finish it with comments on how it works. I made it quickly so Im sorry if I missed something. I'm not 100% sure if my program covers this part -
The last payment may be less than $50 if the debt is small, but do not forget the interest. If you owe $50, then your monthly payment of $50 will not pay off your debt, although it will come close. One month's interest on $50 is only 75 cents.
Although I think I did since if I start the debt at $50, the remaining debt will be 0.75 cents.
#include <iostream>
usingnamespace std;
int main()
{
constint paymentPerMonth = 50; // $50 monthly payment
constdouble interestRate = 0.015; // 1.5% Interest per month
double remainingDebt = 1000.0; // Start with $1000 left to pay
double currentInterest = 0; // Keeps track of each months interest
int amountOfMonths = 0; // Self-explanatory
double totalAmountOfInterestPaid = 0; // Same
bool run = true;
while (run) // run as long as run equals true
{
currentInterest = interestRate * remainingDebt; // How much interest has to be payed per month
totalAmountOfInterestPaid = totalAmountOfInterestPaid + currentInterest; // Adding up all the interests each month
remainingDebt = remainingDebt - (paymentPerMonth - currentInterest); // Paying off the debt, which is 50$ - this months interest
amountOfMonths++; // increase by 1 month each iteration, since one iteration represents a month
if (remainingDebt <= 0) // Once the debt is payed off, ends up at -$2
run = false; // Set run to false to end the loop
}
cout << "Amount of months to pay of $1000 Debt: " << amountOfMonths << endl;
cout << "Total amount of interest payed during the " << amountOfMonths << " months: " << totalAmountOfInterestPaid << endl;
system("pause");
return 0;
}
thank you SO much. I spent hours so confused by this and was getting no where, so I really appreciate the comments and explanations so I can finally understand!!