Thread: calculate monthly payment

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    63

    Question calculate monthly payment

    Hey guys, new to the board and C programming in general. I have this assignment that's giving me problems, don't know what's wrong.


    Monthly Pay=[ rate + rate /([1+rate]^months -1)] X principle
    Where rate of %6 means 6/1200
    Months means number of years x 12

    "Possible data to test:
    Principle 12200
    Rate 7%
    Term in years 5
    Monthly payment is: 241.57"

    My code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    void main ()
    {
        double princ, rate, term, monthly;
            
        printf("Please enter the the principle on your payment: ");
        scanf("%lf", &princ);
        printf("Please enter the rate on your payment: ");
        scanf("%lf", &rate);
        printf("Please enter the term of your payment in years: ");
        scanf("%lf", &term);
        
        rate = (rate/1200);
        term = (term*12);
        
        monthly = ((rate + (rate/(pow((1 + rate),(term-1))))) * princ);
            
        printf("Your monthly payment is: %f", monthly);
        
        return 0;
    
    }
    For my monthly payment I always end up getting half of what is expected. Any ideas?

  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    The problem is the formula you are using. You are doing the following on the denominator.
    Code:
    pow(1+rate, term-1)
    What you should be doing is this:
    Code:
    pow(1+rate, term) - 1
    Btw, it is very bad programming technique to use 'void main()'. You should be using 'int main()' instead.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    63
    Thanks Swarvy! Just compiled it, changed the void as well, and it runs fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. monthly payment from math to C++
    By summerwine in forum C++ Programming
    Replies: 4
    Last Post: 06-10-2010, 05:31 PM
  2. calcuations
    By redmondtab in forum C Programming
    Replies: 39
    Last Post: 09-15-2006, 08:09 PM
  3. Small program that has to calculate miles per gallon
    By Guti14 in forum C++ Programming
    Replies: 6
    Last Post: 01-06-2004, 02:47 PM
  4. table turmoil
    By spirited in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2003, 07:36 AM
  5. Help starting a C program with functions
    By jlmac2001 in forum C Programming
    Replies: 6
    Last Post: 10-12-2002, 02:43 PM