Thursday, July 30, 2009

Need help with C# syntax (I'm making a loan calculator)?

I have the following text boxes on my C# windows application:





amountOfLoan


APR


durationOfLoanInYears





and a label called monthlyPayment.





When you click the calculate button, the monthly payment should be displayed in the monthlyPayment label.





Can someone help me with the code that needs to go behind the Calculate button?





IN CASE IT HELPS, THE FOLLOWING FORMULA IS USED TO COMPUTE THE MONTHLY PAYMENT:





payment = (Principle x Rate) / (1 - (1+Rate)) ^ -numberOfMonths





"Payment is equal to principle times rate divided by 1 minus (1 plus rate) to the negative numberOfMonths power"





----





I just don't know how to express this in C#....

Need help with C# syntax (I'm making a loan calculator)?
Hopefully this does it:





private void button1_Click(object sender, System.EventArgs e)


{


double principal = System.Convert.ToDouble(amountOfLoan.Tex...


double pctrate = System.Convert.ToDouble(APR.Text);


int monthcount = System.Convert.ToInt32(durationOfLoanInY...


double payment = (principal * pctrate) /


Math.Pow(1 - (1 + pctrate), -monthcount);


monthlyPayment.Text = payment.ToString();


}





The Math.Pow object/method provides the exponent calculation
Reply:Don't know why, but answers has a habit of cutting off some lines... Report It

Reply:is there any chance you can send this code example in an email? i'm having trouble replicating the sucess stephanie had, possibly because of the cut off answers. many thanks! Report It

Reply:decimal monthlyPayment = (Decimal.Parse(amountOfLoan.text) * Decimal.Parse(APR.text)) / Math.Pow(1 - ( 1 + Decimal.Parse(APR.text)), Decimal.Parse(durationOfLoanInYears.text...





monthlyPayment.text = monthlyPayment.ToString("c");


No comments:

Post a Comment