Loan payment calculator, payment too high

This is a project for school, and the program will build and run just fine, but the amount calculated for the payment is about 10 times higher than it should be. I've double checked the formula, it's what our instructor gave us and it's the same as other ones i've found on the internet. I'm not sure if I have the format wrong (using pow is confusing for me sometimes) or what is going on here. Any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iomanip>
#include <iostream>
using namespace std;

#include <cmath>

int main()
{
  // input values
  float p = 300000.00;
  float r = 0.05125;
  float n = 360.00;
  int years = 30;


  float s = (p * (pow (( 1 + r ), n) * r) /  (pow(( 1 + r), n) -1));


  // formatting output (see 4.2)
  cout.setf(ios::fixed|ios::showpoint);
  cout << setprecision(2);
  cout << s << "." << endl;
It looks like you are using a yearly interest rate with monthly periods. Divide the interest rate by 12 so that all values are expressed in months.
I can't say that I know much about the formulas used in Load Payment calculation, but yours doesn't look right to me.

I understand p to be the initial investment? And r to be the interest rate? And n to be the number of periods (which seems to be a VERY large number -- periods are not typically days)?

Can you supply a source for the kind of load calculation you are doing?
dhayden - that was exactly what was wrong, thank you for pointing that out to me. Everything works as it should now
Topic archived. No new replies allowed.