Thread: monthly payment from math to C++

  1. #1
    Registered User
    Join Date
    Jun 2010

    monthly payment from math to C++

    so my problem is that i really don't know how to convert the formula from this question into C++

    the monthly payment on a loan may be calculated by the formula

    payment = (Rate * (1+Rate)^N ) * Loan / ((1+Rate)^N - 1)

    rate is the monthly interest rate which is the annual interest rate divided by 12
    12% annula interest rate would be 1 percent monthly interest. N is the number of payments
    Loan is amount of loan
    write a program that asks for there values and displays a report similiar to:

    Loan amount: $ 10000.00
    Monthly Interest Rate: 1%
    Number of Payments: 36
    Monthly Payment: $ 332.14
    Amount Paid Back: $ 11957.15
    Interest Paid: $ 1957.15

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    It would be exactly like that except that there is no ^ operator in C++. You can use the function pow(). You need to #include <math.h>

  3. #3
    Registered User
    Join Date
    Jun 2010
    so what hurts me here, is that i did it with power function.
    and it's not working at all.

  4. #4
    Registered User
    Join Date
    Jun 2010
    that's what i have

    Payment = (Monthly_Interest_Rate * pow(1 + Monthly_Interest_Rate, Number_Of_Payments)) * Loan /( pow(1+Monthly_Interest_Rate, Number_Of_Payments) - 1) ;

  5. #5
    Registered User
    Join Date
    Sep 2009
    is this what you're looking for?

    I used the following formula in my program and with my code, it shows a monthly payment of 332.14 given the 10000.00 amount like your sample output wants.

    payment_amt = (loan_amt * monthy_interest_rate) / (1 - pow(1+monthy_interest_rate,-loan_term_months));

    Quote Originally Posted by C_ntua View Post
    You need to #include <math.h>
    Actually, use the #include <cmath> preprocessor directive. math.h is the old style math header for C++.
    Last edited by x2x3i5x; 06-10-2010 at 09:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doing aweful in math, but decent in CS?
    By psychopath in forum General Discussions
    Replies: 2
    Last Post: 11-04-2009, 09:49 AM
  2. calcuations
    By redmondtab in forum C Programming
    Replies: 39
    Last Post: 09-15-2006, 08:09 PM
  3. how to use operator+() in this code?
    By barlas in forum C++ Programming
    Replies: 10
    Last Post: 07-09-2005, 07:22 PM
  4. toughest math course
    By axon in forum A Brief History of
    Replies: 12
    Last Post: 10-28-2003, 10:06 PM
  5. Help starting a C program with functions
    By jlmac2001 in forum C Programming
    Replies: 6
    Last Post: 10-12-2002, 02:43 PM