Reference no: EM13162275
write a program to tell you how many months it will take to pay off any loan, as well as the total amount of interest paid over the life of the loan.
For example 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 any 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:
heres what i have done, How do i fix it?
//declaring the variables
double totalLoan,
balanceRemaining,
principal,
month,
annualPercentage,
monthlyPayment,
monthlyInterest,
interestPaid,
principalPaid;
cout <<setprecision(2)<<fixed;
cout <<"What is the amount of the loan?";
cin >> totalLoan;
while (totalLoan < 0)
{
cout <<"Invalid entry. Please enter a positive value only";
cin >> totalLoan;
}
cout <<"What is the annual percentage rate?";
cin >> annualPercentage;
while (annualPercentage < 0)
{
cout <<"Invalid entry. Please enter a positive value only";
cin >> annualPercentage;
}
cout << "Enter your monthly payment: "<<endl;
cin >> monthlyPayment;
cout <<endl;
cout <<endl;
cout <<"Month"<<setw(15)<<"Principal"<<setw(13)<<"Interest"<<setw(13)<<"Principal"<<setw(13)<<"Remaining";
cout <<setw(50)<<"paid"<<setw(12)<<"paid"<<setw(17)<<"Balance\n";
monthlyInterest = (annualPercentage/(12*100));
for (month = totalLoan; month >=0; ++month)
{
interestPaid= monthlyInterest*totalLoan;
principalPaid= monthlyPayment-interestPaid;
balanceRemaining=totalLoan-principalPaid;
principal=balanceRemaining+principalPaid;
cout <<month<<setw(15)<<principal<<setw(13)<<interestPaid<<setw(13)<<principalPaid<<setw(13)<<balanceRemaining;
}
getch();
}