Thread: calcuations

  1. #31
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    the biggest one is the one that the teacher gave us to use. If that one is not correct it puts the rest of my calculations off. I have gone over and over this program and am not seeing the issues with the math. That is why i'm asking for some help. I don't see where i can make is simpiler.

  2. #32
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > I don't see where i can make is simpiler.
    How about reformat for readability
    Code:
      PaymentAmount = pow((1+i/12),n) * 
                      (i/12*a) / 
                      pow((1+i/12),n) -
                      1;
    Or break the calculation into more easily manageable steps, which you can inspect for correctness.
    Code:
      double c1, c2, c3;
        c1 = pow((1+i/12),n);
        c2 = (i/12*a);
        c3 = pow((1+i/12),n);
        PaymentAmount = c1 * c2 / c3 - 1;
    Having done that, it seems that your two pow() sub-expressions cancel out, so perhaps the whole thing is wrong.

    We can help with the syntax, but we can't really guess which math function you're supposed to be using to begin with.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #33
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    One thing I've noticed is the interest rate (i) in that formula must be divided by 100 first. For example if you enter 12 (in percent) for the interest rate, then the formula requires 0.12. So what you could do is use another variable (maybe InterestRate) when the user enters it, then make i be (InterestRate/100).
    Code:
    //User enters interest rate
    i = InterestRate / 100.;
    Last edited by swoopy; 09-15-2006 at 12:14 PM.

  4. #34
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by swoopy
    One thing I've noticed is the interest rate (i) in that formula must be divided by 100 first. For example if you enter 12 (in percent) for the interest rate, then the formula requires 0.12. So what you could do is use another variable (maybe InterestRate) when the user enters it, then make i be (InterestRate/100).
    Code:
    //User enters interest rate
    i = InterestRate / 100.;
    Interest rates are in percent, and if there's one thing I recall from math class it's this:

    "Percent Means Hundreths"

    I wouldn't change that. I've got an amotization program around here, I'll see if I can dig it up.

    Back in a bit.

    Adak

  5. #35
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    I made some changes to the program and then ran it, it seemed to just calculate
    a repayment very close to the interest, paying off next to nothing.
    I plugged the figures into a calculator to calcualte the repayment on an interest only formula
    and it came up with the same amount.
    Is it the correct formula?

  6. #36
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by esbo
    I made some changes to the program and then ran it, it seemed to just calculate
    a repayment very close to the interest, paying off next to nothing.
    I plugged the figures into a calculator to calcualte the repayment on an interest only formula
    and it came up with the same amount.
    Is it the correct formula?
    I'm still looking for the program, but here's a link to an amortization calculator:

    http://www.amortization-calc.com/

    An amortized loan should be paying off a lot of interest at first, but increasingly paying off more principal with each payment. All the payments are the same amount, of course.

    Added Note:
    This is the best website I've found with the formula and explanations, so far:

    http://www.hughchou.org/calc/formula.html

    Check it out, it's good!

    Adak
    Last edited by Adak; 09-15-2006 at 05:45 PM.

  7. #37
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    I believe the correct formula is final formula given on the following link.
    You will note the first part of the formula is the one used in the OP program (or at least the one he tried to use) and then there is another bit. This 'second bit' is the bit which repays the principle, the first bit is for the interest only).
    http://ray.met.fsu.edu/~bret/amortiz...n%20formula%22

    It shouldn't be too difficult to program the second bit in. It should work then!!!


    Actually I now think that is wrong, the second bit of the equation is a lump sum you pay off at theend of the term and this will be zero for a repayment mortages so it would be zero
    Last edited by esbo; 09-15-2006 at 05:03 PM.

  8. #38
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794

    Thumbs up

    This seems to work. I have changed a few of the terms and fiddled with it a bit
    but it should be easy to see what is what.


    Code:
    
    /*************************************************************  
    File Name:     Tmitchellwk1
    Descreption:   Display Loan Amortization Schedule
    Date:          August 28th, 2006
    Desinger;      Tabatha Mitchell
    Assugnment:    week1
    Fuctions:      None
    **************************************************************/
    #include <stdio.h>
    
    /*Program to compute Amortization Schedule*/
    
    main  ()
    {
       
       int   TermLoan,  // length of the loan
             PaymentNumber,  //number of payments made
              Numberofmonths, //Number of months in the loan
             count,  
              n; //Letters used for the caculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to intrest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //intrest rate on loan
               a,i,
               NewBlance, //amount of new amount owed
               PaymentAmount;  //amount paid to loan       
           
     //start of main program
       printf ("Please enter in loan amount, Term of Loan and Intrest Rate.\n");
       scanf  ("%lf%d%lf", &LoanAmount, &TermLoan, &InterestRate);
       
       CurrentBlance = LoanAmount;
       Numberofmonths = TermLoan * 12 ;  //calculate numbers of months
       i = InterestRate;
       n = Numberofmonths;
       a = CurrentBlance;
       NewBlance=a;
       
    printf ("\nAmortization Schedule\n");
    printf ("_____________________\n");
    printf ("PaymentNumber, LoanBlance, PaymentAmount, AmountPrinciple, AmountInterest, NewBlance\n");
     PaymentNumber = 0;  
       count =0;
       
          while(PaymentNumber < Numberofmonths) //start of while loop
            { 
             
               PaymentAmount = a*(i/12)*pow((1+i/12),n)/(  pow((1+i/12),n) -1);
               PaymentNumber++; //Start number of months for amortization schedule
               count++; //Start counter for displaying specific number of payments
               AmountInterest =  NewBlance * i/12;
               AmountPrinciple =  PaymentAmount - AmountInterest;
               NewBlance =  NewBlance -  PaymentAmount + AmountInterest;
    
    
              printf ("Payment No %.2d  ",  PaymentNumber);
               printf ("  Payment Ammt %.2lf", PaymentAmount);
              printf ("  Amount prin %.2f ", AmountPrinciple);
              printf  ("  Princiople Int %.2lf ", AmountInterest);
              printf ("Newbalance %.2f\n", NewBlance);
    
          
            }  //end of while loop 
    
    /* getchar ();*/
    getchar ();
    printf ("hit enter to end");
    return 0;         
    }


    Output:-

    Please enter in loan amount, Term of Loan and Intrest Rate.
    30000 25 0.070

    Amortization Schedule
    _____________________
    PaymentNumber, LoanBlance, PaymentAmount, AmountPrinciple, AmountInterest, NewBlance
    Payment No 1 Payment Ammt 212.03 Amount prin 37.03 Princiople Int 175.00 Newbalance 29962.97
    Payment No 2 Payment Ammt 212.03 Amount prin 37.25 Princiople Int 174.78 Newbalance 29925.72
    Payment No 3 Payment Ammt 212.03 Amount prin 37.47 Princiople Int 174.57 Newbalance 29888.25
    Payment No 4 Payment Ammt 212.03 Amount prin 37.69 Princiople Int 174.35 Newbalance 29850.56
    Payment No 5 Payment Ammt 212.03 Amount prin 37.91 Princiople Int 174.13 Newbalance 29812.66
    Payment No 6 Payment Ammt 212.03 Amount prin 38.13 Princiople Int 173.91 Newbalance 29774.53
    Payment No 7 Payment Ammt 212.03 Amount prin 38.35 Princiople Int 173.68 Newbalance 29736.18
    Payment No 8 Payment Ammt 212.03 Amount prin 38.57 Princiople Int 173.46 Newbalance 29697.61
    Payment No 9 Payment Ammt 212.03 Amount prin 38.80 Princiople Int 173.24 Newbalance 29658.81
    Payment No 10 Payment Ammt 212.03 Amount prin 39.02 Princiople Int 173.01 Newbalance 29619.79
    <<<snipped for brevity>>>
    Payment No 296 Payment Ammt 212.03 Amount prin 205.96 Princiople Int 6.08 Newbalance 835.91
    Payment No 297 Payment Ammt 212.03 Amount prin 207.16 Princiople Int 4.88 Newbalance 628.75
    Payment No 298 Payment Ammt 212.03 Amount prin 208.37 Princiople Int 3.67 Newbalance 420.39
    Payment No 299 Payment Ammt 212.03 Amount prin 209.58 Princiople Int 2.45 Newbalance 210.80
    Payment No 300 Payment Ammt 212.03 Amount prin 210.80 Princiople Int 1.23 Newbalance 0.00
    hit enter to end

  9. #39
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    A key point is the extra brackets added to
    Code:
    PaymentAmount = a*(i/12)*pow((1+i/12),n)/pow((1+i/12),n) -1;
    to get :-
    Code:
    PaymentAmount = a*(i/12)*pow((1+i/12),n)/(  pow((1+i/12),n) -1 );

  10. #40
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Looks like you've got it ol' chap!! :P

    Congrats!

    Adak

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM