Results 1 to 3 of 3

Thread: COding help, output is wrong

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    40

    COding help, output is wrong

    Code:
    double getPaymentAmount(double interest, int numberOfMonths, double principal)
    {
    	double getPaymentAmount;
    		getPaymentAmount = (powf((1+interest),numberOfMonths)/
    							(powf((1+interest),numberOfMonths)-1)
    							*principal*interest);
    							
    	return getPaymentAmount;
    }
    //----------------------------------------------------------------------------
    //
    //----------------------------------------------------------------------------
    double getLoanAmount(double interest, int numberOfMonths, double payment)
    {
    	double getLoanAmount;
    		getLoanAmount = (powf((1+interest),numberOfMonths) - 1*payment)/
    						(interest*powf((1+interest),numberOfMonths));
    
    	return getLoanAmount;
    
    }
    //----------------------------------------------------------------------------
    //
    //----------------------------------------------------------------------------
    int getNumberOfMonths(double interest, double payment, double principal)
    {
    	int getNumberOfMonths;
    		getNumberOfMonths = (log(payment)-log(payment-(principal*interest))) /
    							(log(1+interest));
    
    	return getNumberOfMonths;
    payment = (1 + i)^ months * principal * i

    --------------------------------------------------------------------------------

    (1 + i) months - 1


    principal = (1 + i )^ months - 1 * payment

    --------------------------------------------------------------------------------

    i * (1 + i ) months


    months = log( payment ) - log( payment - (principal * i ))

    --------------------------------------------------------------------------------

    log( 1 + i )

    this is the regular formula. can someone tell me what im doing wrong here?

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    40

    Re: COding help, output is wrong

    --------------------- means divide it by
    (1+i)^months
    -------------- * principal * i
    (1+i)^months -1

    ect,,,

  3. #3
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: COding help, output is wrong

    What are the inputs and expected outputs? What are the actuals? Also this part of your formula doesn't make sense to me:
    principal = (1 + i )^ months - 1 * payment
    Why would you be multiplying the payment by 1? It's not going to do anything. Should it be:
    principal = (1 + i )^(months - 1) * payment
    ??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width