Financial Program assistance


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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*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.
You posted it here, what do you want actually?
http://www.cplusplus.com/forum/general/14990/

I had the core program created and was trying to get an extra function added in that would calculate the interest paid after each month and then print out the sum of those amounts at the end of the program once the loan was paid off. I described it better in this thread : http://www.cplusplus.com/forum/general/15111/ that was the one I needed, but it was due last night. I was able to get the core program which is all that was required. the other part was just something extra I wanted to add in based on what co-workers said they would like for the program to do if they had needed to use it.

I appreciate your help. Will possibly be posting other program assistance threads over the semester. Hope no one gets annoyed too much, tho it does give something to do for the retired programmers that get bored with retirement.

Thanks again
Topic archived. No new replies allowed.