My instructor wants us to create a program that relates to some event we have recently gone through and I need help to get the rest of the code to work.
Scenario I passed by the instructor is : I just got a car which my grandfather paid in advance and I have to pay him back.Thus I have completed a program that allows the user to input the amount of a loan, the interest compounded monthly, and the desired monthly payment. Which in turn outputs what the balance would be at the end of each month until it reaches the point which the balance is $0.
I need a way to calculate how much interest is paid in total at the end of the loan period. As in, calculate what the interest each month is and then sum it up at end of loan period and then output it.
I am using Visual Studio 2008 environment. Here is my program thus far:
/*This program provides a user help to determine how long they need to make
monthly payments of a certain amount to pay off a debt at a certain rate of interest */
#include <iostream>
using namespace std;
int main()
{
double monthlyPayment, balance, interestRate, intrestSum;
int month = 1;
cout.setf(ios::fixed); // These lines force currency format in output
cout.setf(ios::showpoint); //to 2 decimal pts
cout.precision(2);
cout << "Enter the current balance of your loan: $";
cin >> balance;
cout << "Enter the interest rate (compounded monthly) : ";
cin >> interestRate;
cout << "Enter the desired monthly payment : $";
cin >> monthlyPayment;
while (interestRate >= 1)
interestRate = interestRate / 100;
balance = balance * (1 + interestRate / 12) - monthlyPayment;
cout<<"After month "<<month<<", your balance is : $"<<balance<<endl;
while (balance > 0)
{
month++;
if (balance < monthlyPayment)
{
balance = balance - balance;
cout << "You have paid off the loan after " << month <<" months's. Congratulations!" << endl;
}
else
{
balance = balance * (1 + interestRate / 12) - monthlyPayment;
interestTotal
cout << "After month " << month << ", your balance is : $" << balance << endl;
}
return 0;
}
Here is an example output:
Enter the current balance of your loan: $250
Enter the interest rate (compounded monthly) : 12.9
Enter the desired monthly payment : $50
After month 1, your balance is : $202.69
After month 2, your balance is : $154.87
After month 3, your balance is : $106.53
After month 4, your balance is : $57.68
After month 5, your balance is : $8.30
You have paid off the loan after 6 months's. Congratulations!
Press any key to continue . . .
Once again, I would like to add the line:
You have paid a total of : $XX.XX in interest over the life of the loan.
where the X's is the sum of what the intrest would be each month. Due to the value of balance changing each month, the intrest amount each month would also change so it's not as simple as intrest rate * value of month at the end.
This is the first C++ class I have taken and someone already offered a code example the wrote but it had classes and much more complex coding than we have learned in class and I know that the instructor wouldn't accept such.
Any help will be greatly appreciated.