Question with exponents

This is only my 5th program.

I am writing a program that will calculate the monthly payment on a loan.

They tell you to use the formula :

Payment = Rate * (1+Rate)^N / ((1+Rate)^N - 1) * L

N = number of payments

L = loan amount

So here is the code i wrote.

MonthlyPayment = (MonthlyIntRate * pow((1.0 + MonthlyIntRate), NumberOfPayments)) / (pow((1.0 + MonthlyIntRate),NumberOfPayments) - 1.0);

All the variables are double. And im using cmath.

The program will compile just fine, but it will only output with whatever I enter for the MonthlyIntRate.

Help!
I don't see you have included the loan amount in the code.
I missed that when I was copying, but its there and im still having the same issue.
How do you miss something with copy and paste? Paste the exact code, don't type it by hand.
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <stdlib.h>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
  
  double LoanAmt,
         MonthlyIntRate,
         NumberOfPayments,
         MonthlyPayment,
         AmtPaidBack,
         IntPaid;
         
         
         cout << "How much is your loan amount? ";
         cin >> LoanAmt;
         
         cout << "\n \n";
         
         cout << "What is the monthly interest rate? ";
         cin >> MonthlyIntRate;
         
         cout << "\n \n";
         
         cout << "Number of payments? ";
         cin >> NumberOfPayments;
         
         cout << "\n \n";
         
         // Calculations
         // I couldn't get the math to come out right.
         
         
         MonthlyPayment = (MonthlyIntRate * pow((1.0 + MonthlyIntRate), NumberOfPayments)) / 
         (pow((1.0 + MonthlyIntRate),NumberOfPayments) - 1.0) * LoanAmt;
         
         
         
         
         cout << "\n \n";
         
        
        
         
         
         
         // Displays the calculations
         
         cout << "Loan Amount:                   $" << LoanAmt << "\n";
         cout << "Monthly Interest Rate:          " << MonthlyIntRate << "\n";
         cout << "Number of Payments:             " << NumberOfPayments << "\n";
         cout << "Monthly Payment:               $" << MonthlyPayment << "\n";
         cout << "Amount Paid Back:              $" << AmtPaidBack << "\n";
         cout << "Interest Paid:                 $" << IntPaid << "\n";
  
  
  
  
  
  
  
  
  
  
  
  system("PAUSE");	
  return 0;
}
Topic archived. No new replies allowed.