Thread: calcuations

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

    Question calcuations

    i need help with the calcuations. I know that I'm off some where just not to sure where.

    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;
       
    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
            { 
            printf ("at line 2\n");          
               PaymentAmount = (1+i/12)pow(n)*(i/12*a)/(1+i/12)pow(n-1);
               PaymentNumber++; //Start number of months for amortization schedule
               count++; //Start counter for displaying specific number of payments
               AmountInterest =  a * i;
               AmountPrinciple =  PaymentAmount - AmountInterest;
               NewBlance = a - NewBlance;
               LoanBlance = a  - AmountPrinciple;
              printf ("%d\n",  PaymentNumber);
              printf ("%lf\n", LoanBlance);
              printf ("%lf\n", PaymentAmount);
              printf ("%f\n", AmountPrinciple);
              printf  ("%lf\n", AmountInterest);
              printf ("%f\n", NewBlance);
    
              printf ("at  line 3\n");
            }  //end of while loop 
    
    getchar ();
    getchar ();
    printf ("hit enter to end");
    return 0;         
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > PaymentAmount = (1+i/12)pow(n)*(i/12*a)/(1+i/12)pow(n-1);
    C doesn't understand xy as being x * y
    You need a few more explicit operators in there.
    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. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    so i need it to look like

    (1+i/12)pow*(n)*(i/12*a)/(1+i/12)pow*(n-1);
    what am i missing

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I was thinking more like (1+i/12) * pow(n)

    Not that it makes much sense, since all the pow() functions I know about take two parameters.

    Maybe you could start by fixing all the warnings which this code no doubt generates.
    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.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    [ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n – 1 ]

    this is the way that i started. but it keep getting the error when i use it jsut that way that it is an invail unary. when i go to compile it

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    [ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n – 1 ]
    There's the two arguments you should be passing to pow. The second argument is the exponent.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    thats what i don't understand so it would look like this
    [ (1 + i / 12) pow (n) * (i / 12 * a) ] / [ (1 + i / 12) pow( n – 1) ]
    or

    pow ( (1 + i / 12) ** n * (i / 12 * a) ) /pow ( (1 + i / 12) ** n – 1 )

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Do you know what the calculation does? Do you understand exponents? If so then go look up the man page for pow(). Here it is: http://www.hmug.org/man/3/pow.php

    If you understand exponents then you should be able to understand that documentation. Rather than fumbling around and just guessing at what's right, it's better to just find out how to do it the right way in the first place.
    If you understand what you're doing, you're not learning anything.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    And here's a second reference:
    http://www.cppreference.com/stdmath/pow.html
    And you must include <math.h>, something you are missing in your code.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    [ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n – 1 ]
    I highlighted the exponent. That should be your second argument to the pow function.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    Quote Originally Posted by swoopy
    [ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n – 1 ]
    I highlighted the exponent. That should be your second argument to the pow function.
    I'm stil having issues with this code.
    //[ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n – 1 ]
    PaymentAmount= pow((1 + i/12), n *(i/12 * a))/ pow((1 + i/12), n - 1); You need to understand and implement operator precedence here. Both of your pow statements have incorrect exponents. According to the formula the exponent of the first pow should just be n. And the exponent of the second pow should also just be n. not to sure how to write this.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Ok, unfortunately the C language has no operator for **. To take something to the power of something else, you must call a library function (pow). The function pow requires two arguments:
    (1) The expression before the **
    (2) The expression after the **

    [ (1 + i / 12) ** n * (i / 12 * a) ] / [ (1 + i / 12) ** n – 1 ]

    So substituting pow for **:
    Code:
    ( pow(1 + i / 12,  n) * (i / 12 * a) ) /  (pow(1 + i / 12,  n) – 1 )

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    i had pow((1 + i/12), n *(i/12 * a))/ pow((1 + i/12), n - 1); and was told that it was wrong. so your saying it should be ( pow(1 + i / 12, n) * (i / 12 * a) ) / (pow(1 + i / 12, n) – 1 ) that is alot differnt then what i have

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >i had pow((1 + i/12), n *(i/12 * a))/ pow((1 + i/12), n - 1)

    Notice above, you've got n * (1/12 * a) as the exponent to pow. Looking at your original formula, it should just be n.

    Then look at your second call to pow. You've got n - 1 as the exponent. Looking at your original formula, it should just be n.

    It would probably help if you broke up the calculations into several parts. Just do one step at a time. For example i/12 occurs three times, and 1 + i/12 occurs twice.
    Last edited by swoopy; 09-13-2006 at 05:31 PM.

  15. #15
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    It looks as though the original formula was slightly incorrect, because (ignoring the incorrect usage of the pow() function, but taking it as it it did work correctly):-

    (1+i/12)pow(n)*(i/12*a)/(1+i/12)pow(n-1) is the same as

    (i/12*a) * (1+i/12)pow(n)/(1+i/12)pow(n-1)

    In which case you could divide the top and bottom by (1+i/12)pow(n-1) to get

    (i/12*a) * (1+i/12)pow(1)/1 or more simply.

    (i/12*a) * (1+i/12)

    (because for example 5*5*5*5/5*5*5 = 5)


    Hence the formula posted by swoopy would appear to be correct. It seems you may have mis-read the formular from somewhere, like here:-

    http://www.answers.com/topic/amortization-business

    Where it may be ambigious. Or maybe from a plain text version of the formula which might be even more difficult to interpretate due to the limitations of plain text. But as I said the formula you used originally would simplify significantly so you almost certainly mis-interpreted it.

    I once wrote a program to calculate the same result by an iterative (trial and error) method because the maths, as you can see, is pretty complicated, similar to this I believe:-

    http://ray.met.fsu.edu/~bret/amortiz...n%20formula%22

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