Monthly Payment Loan

I'm doing the Loan Monthly payment homework. Everything works fine, but the formula just doesn't work, like I don't know what else to do, somewhere I read that we have to divide something by 12, but my teacher didn't mention that so I'm so confused!! Been trying to do it for 3 hours!

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
//TaxLab with input

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

void main()
{

	double loan;
	double r=0;
	double n=0;
	double b =(1+r/100);
	double e =n;

	cout << fixed << setprecision(2);

	cout<<"Enter loan amount: $"; setw(5);
	cin>> loan; 
	cout << endl;
	
	cout<<"Annual Interest Rate: "; setw(5);
	cin>> r;
	cout<< endl;

	cout<<"Number of Payments: " << setw(5);
	cin>> n;
	cout<<endl;

//Everything works until this point.

	cout<<"Monthly Payment: $" << setw(5)<< r*pow(b,e)/((pow(b,e))-1) << endl;

// I can't work on the bottom two because I don't have the correct formula!! Help!

	cout<<"What You'll Pay Back: $" << setw(5)<< r <<endl;

	cout<<"Interest Paid: $" <<setw(5)<< r <<endl;
Line Number 33 Is Giving Infinite Monthly Payment: $ inf
Correct this and it should work fine. There must never be a case where denominator is "0" otherwise the program will fail unless you handle the exception and correct it.
If I am not mistaken
1
2
3
4
5
6
r*pow(b,e)/((pow(b,e))-1)
// r = user input
// b = 1 + 0 / 100
// e = 0
// in other words
// r * pow(1, 0) / ((pow(1, 0)) - 1) 
Last edited on
can u post the code again with all the variable and their names... like what is each of them supposed to be?
and if you know the formula for interest post that too...
i will try to help...
okay, i did some googling and found these on loan payment

http://www.1728.org/loanform.htm

http://www.financeformulas.net/Loan_Payment_Formula.html

http://www.wikihow.com/Calculate-a-Loan-Payment

make sure your equation is consistent with these.

P = ( r * A ) / ( 1 - (1+r)-N)

Where,
P = Payment Amount
A = Loan Amount
r = Rate of Interest (compounded)
N = Number of Payments

Rate of Interest Compounded is,
If Monthly, r = i / 1200 and N = n * 12
If Quarterly, r = i / 400 and N = n * 4
If Half yearly, r = i / 200 and N = n * 2
If Yearly, r = i / 100 and N = n
Topic archived. No new replies allowed.