# calcuations

Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last
• 09-08-2006
redmondtab
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;        }```
• 09-08-2006
Salem
> 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.
• 09-08-2006
redmondtab
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
• 09-08-2006
Salem
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.
• 09-08-2006
redmondtab
[ (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
• 09-08-2006
swoopy
[ (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.
• 09-08-2006
redmondtab
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 )
• 09-08-2006
itsme86
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.
• 09-08-2006
swoopy
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.
• 09-08-2006
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.
• 09-13-2006
redmondtab
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.
• 09-13-2006
swoopy
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 )`
• 09-13-2006
redmondtab
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
• 09-13-2006
swoopy
>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.
• 09-13-2006
esbo
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:-