Loan Program

Me and my friend are trying to solve a homework problem but we don’t have enough background knowledge to fully complete it.

The problem is :

-create a program that operates loans
-user must enter the following
1. Amount the user wants to borrow
2. For how long the user wants to make the payment (in years)
3.The rate of the interest (Ex: 22% is input as 0.22)

- Calculate the sum of the interest paid by the user at the end of the program

This equation will calculate the the amount the user will have to pay monthly:

PMT = A * ( B / C ) * ( 1 / ( 1 - ( 1 / ( 1 + ( B / C ) ) ^( D * C ) ) ) )

A, The amount borrowed (Ex, 4000)
B, The yearly interest rate (Ex, 0.22)
C, Interval of the payment (Ex, 12)
D, The period of the loan in years (Ex, 4)

..............................................................................

We want the output to look like this,

..............................................................................

********Welcome to My program*******

Please Enter how much you want to borrow : 5000
Please enter the yearly interest rate : 0.4
Please enter the period of the loan in years : 4

The monthly Payment is 210.23 for 48 Months ( 4 years )

Month , Start Balance , Payment , Principal , Interest , End Balance

1 , 3000.00 ,127.35 , 43.56 , 166.67 , 4956.44
... , 4956.44 ,127.35 , $$.$$ , $$.$$ , $$.$$
48 , $$.$$$$ ,127.35 , $$.$$ , $$.$$ , 0.00



The sum of the interest paid in 48 months is : $$$$$$

Enter another loan ? (Y/N) :

..................................................................

-For the above example the payment is calculated using the first equation.

-Interest is 1/12 th of 40% so it is 1/12 x 0.4 x 5000 = 166.67

-Amount borrowed = 210.23 - 166.67 = 43.56

-The end balance = The initial balance - The amount borrowed
= 5000 - 43.56
= 4956.44


........................................................................

This is what we have so far, We want to keep it as simple as possible.


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
50
51
52
53
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()

{
	float L; //loan amount
	float r; //annual percentage rate
	float m; //number of payments per year
	float t; //how long the loan is for in years
	float i; 
	float k; //number of payments made
	float R; //periodic payment
	float LPrime = 0; //unpaid balance after making k payments
	int exit;

	cout << "Please enter the loan amount." << endl;
	cout << "$";
	cin >> L;
	cout << " " << endl;
	cout << "Please enter the annual percentage rate." << endl;
	cout << "%";
	cin >> r;
	cout << " " << endl;
	cout << "Please enter the number of payments to be made per year." << endl;
	cin >> m;
	cout << " " << endl;
	cout << "Please enter the number of years the loan is for." << endl;
	cin >> t;
	cout << " " << endl;
	cout << "Please enter the number of payments that have been made." << endl;
	cin >> k;
			
	for (R = 0; LPrime <= L; LPrime--)
	{
		i = (r / m);
		R = ((L * i) / (1 - pow((1 + i), (-1 * m * t))));
		LPrime = ((R * (1 - pow((1 + i), (-1 * m * t * -k))) / (i)));
		break;
	}
	
	cout << " " << endl;
	cout << "The periodic payment is $" << R << "." << endl;
	cout << " " << endl;
	cout << "The unpaid balance is $" << LPrime << "." << endl;
	cout << " " << endl;
	cout << "Type 'exit' to exit." << endl;
	cin >> exit;
	
}


We can't seem to get it as the output we want. Any suggestions would be greatly appreciated.


Last edited on
State what exactly the problem is. Also, wrap your code in [code] tags to make it readable.
Yea problem would be nice. If it's just strictly formatting, then messing with it enough should get you there.

P.S.
Name your variables so they're more helpful. We'll appreciate, your partner will appreciate it, and your teacher will appreciate it. Not to mention you when you go back to look at this program in a year.
Topic archived. No new replies allowed.