Thread: calcuations

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    104

    Angry

    ok i got the pow formula to work. KNow my issues is with my AmountIntrest .
    Code:
    AmountInterest = a  * (1 + i/12);
    Here you are applying a years worth of interest each month. You read in an annual interest rate. As was done in the formula I provided, you have to adjust that for just one month.
    so would that mean ti would have to write it as
    Code:
     AmountInterest = ( pow(1 + i / 12,  n)*a;
    This way it si deviding the months by the interest the * by the currentanount ler me knwo if you want to see the rest of the program.

  2. #17
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by redmondtab
    ok i got the pow formula to work. KNow my issues is with my AmountIntrest .
    Code:
    AmountInterest = a  * (1 + i/12);
    Here you are applying a years worth of interest each month. You read in an annual interest rate. As was done in the formula I provided, you have to adjust that for just one month.
    so would that mean ti would have to write it as
    Code:
     AmountInterest = ( pow(1 + i / 12,  n)*a;
    This way it si deviding the months by the interest the * by the currentanount ler me knwo if you want to see the rest of the program.
    .
    I don't think you need to be using the pow function at all for this bit. The monthly interest would be the amount outstanding times the interest rate divided by 12.

    So that seems to be simply:- a*i/12. (a =ammount outstanding)
    (Of course I am assuming that the interest rate is defined as "the interest rate which can be applied monthly to pay off the loan ).

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    yeah i finally under stand that know. I was trying to take it from a % to a demical. Which i did not need to do. Go figure. THanks for the help on this one

  4. #19
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I think your logic in simplifing the formula is flawed, but I can't prove it.
    Code:
    ( pow(1 + i / 12,  n) * (i / 12 * a) ) /  (pow(1 + i / 12,  n) – 1 )
    (because for example 5*5*5*5/5*5*5 = 5)
    No it doesn't, unless you meant (5*5*5*5)/(5*5*5) = 5.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #20
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by dwks
    I think your logic in simplifing the formula is flawed, but I can't prove it.
    Code:
    ( pow(1 + i / 12,  n) * (i / 12 * a) ) /  (pow(1 + i / 12,  n) – 1 )

    No it doesn't, unless you meant (5*5*5*5)/(5*5*5) = 5.
    Yes that is what I mean't maybe I should have put:-

    5*5*5*5
    -----------
    5*5*5


    Which was what I was thinking.

  6. #21
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Maybe . . . but I don't think your local compiler will like so many minuses in a row. I know what you mean.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #22
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by dwks
    I think your logic in simplifing the formula is flawed, but I can't prove it.
    Code:
    ( pow(1 + i / 12,  n) * (i / 12 * a) ) /  (pow(1 + i / 12,  n) – 1 )
    Refering to that bit, the quoted formula above is not the formula I simplified, I simplified
    the formula he mistakenly originally used. :-
    ( pow(1 + i / 12, n) * (i / 12 * a) ) / (pow(1 + i / 12, n – 1 ))

    The formula you quoted cannot be simplified, or at least no one has managed it yet
    (and I am sure many eminent mathemeticains have tried!!)

  8. #23
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by esbo
    Refering to that bit, the quoted formula above is not the formula I simplified, I simplified
    the formula he mistakenly originally used. :-
    ( pow(1 + i / 12, n) * (i / 12 * a) ) / (pow(1 + i / 12, n – 1 ))

    The formula you quoted cannot be simplified, or at least no one has managed it yet
    (and I am sure many eminent mathemeticains have tried!!)
    That's what I was trying to point out.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #24
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    ok i need my teach is dead set that is is correct. Can some one pleae run this and tell me if the get teh correct answers

    Code:
    /*************************************************************  
    File Name:     Tmitchellwk1
    Description:   Display Loan Amortization Schedule
    Date:          August 28th, 2006
    Designer;      Tabatha Mitchell
    Assignment:    week1
    Functions:      None
    **************************************************************/
    #include <stdio.h>
    #include <math.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,c; //Letters used for the calculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to interest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //interest 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 in months and Interest Rate.\n");
      
     
            while (scanf("%lf%d%lf", &LoanAmount, &TermLoan, &InterestRate) != 3
                         || (LoanAmount < 0 || TermLoan < 0 || InterestRate < 0 ))
              {
                 while ((c = getchar()) != '\n' && c != EOF);
                 printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n"); 
             }         
       CurrentBlance = LoanAmount;
       Numberofmonths = TermLoan; 
         i = InterestRate;
                   n = Numberofmonths;
                   a = CurrentBlance;
                    PaymentNumber = 0;
                    count = 0;  
       
                    
    printf ("\amortization Schedule\n");
    printf ("_____________________\n");
    
              
            PaymentAmount = pow((1+i/12),n)*(i/12*a)/pow((1+i/12),n)-1;        
       
                while(PaymentNumber < Numberofmonths)
               {   
                  //[ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n – 1 ]
                        
               PaymentNumber++; //Start number of months for amortization schedule
               count++;
               AmountInterest = a  * (i/12);  
               AmountPrinciple = PaymentAmount - AmountInterest;
               LoanBlance = a -AmountPrinciple;
               printf ("CurrentBlance %.2f\n", a);
               printf ("InterestRate %.2f\n", i);
              printf ("PaymentNumber %d\n",  PaymentNumber);
              printf ("LoanBlance  %.2f\n", LoanBlance);
              printf ("PaymentAmount %.2f\n", PaymentAmount);
              printf ("AmountPrinciple %.2f\n", AmountPrinciple);
              printf  ("AmountInterest %.2f\n", AmountInterest);
              printf ("_______________________\n\n");
              a = LoanBlance;  
                    }//end of while loop 
    
    getchar ();
    getchar ();
    printf ("hit enter to end");
    return 0;         
    }

  10. #25
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    getchar ();
    getchar ();
    printf ("hit enter to end");
    The user will never see that printf(); put it before the getchar()s. And in case there's more than just a newline sitting in the input buffer you might want to do this instead:
    Code:
    int c;
    while((c = getchar()) != '\n' && c != EOF);
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #26
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    Dose the math work for you. I'm getting wrong number but was told that this is how the calcualtions should be?

  12. #27
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Start with a really simple test, something which is paid off in say 3 months, so you don't get vast amounts of output to deal with.

    Do you have a specimen output to compare against?

    Have you done the calculations by hand?

    Have you tried to use the debugger - a marvellous program which allows you to step through your code one line at a time, and examine all the variables as you're going along. Most good compilers come with some sort of a debugger.
    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.

  13. #28
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    >        PaymentAmount = pow((1+i/12),n)*(i/12*a)/pow((1+i/12),n)-1;
    I think you're missing some parentheses. I think it should be:
    Code:
            PaymentAmount = ( pow((1+i/12),n)*(i/12*a) ) / ( pow((1+i/12),n)-1 );

  14. #29
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    Ive tried that and it is not giving me the right payment amount.

    i did something simple and this is what i came up with
    Please enter in loan amount, Term of Loan in months and Interest Rate.

    1000.00 12 12

    Amortization Schedule

    _____________________

    CurrentBlance 1000.00

    InterestRate 12.00

    PaymentNumber 1

    LoanBlance 1001.00

    PaymentAmount 999.00

    AmountPrinciple -1.00

    AmountInterest 1000.00

    _______________________



    CurrentBlance 1001.00

    InterestRate 12.00

    PaymentNumber 2

    LoanBlance 1003.00

    PaymentAmount 999.00

    AmountPrinciple -2.00

    AmountInterest 1001.00

    _______________________



    CurrentBlance 1003.00

    InterestRate 12.00

    PaymentNumber 3

    LoanBlance 1007.00

    PaymentAmount 999.00

    AmountPrinciple -4.00

    AmountInterest 1003.00

    _______________________
    Last edited by redmondtab; 09-15-2006 at 07:41 AM.

  15. #30
    Java and C newbie Xero's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    21
    I suggest that if you're doing a complicated calculations, why not take it one at a time, rather than making a single line of code full blast.

    After doing the correct formula, then shrink it to single line.
    Code:
    Noob - a word used to describe someone like me. (noun)

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