i am still new to learning C# and was wondering if i could get some help. I am writing a program C# and Windows forms so that users can calculate their monthly payments and interest for a mortgage. The equation i have for the payments is: Payment = p * r / ( 1 - ( 1 + r ) ^ ( -n ) ) Where p is the amount of the loan, r is the monthly interest rate given as a number from 0 (for 0 percent) and 1 (for 100 percent), n is the duration of the loan in months Then the formula for the total interest paid is: total interest = n * payment –p
Now i have tried entering all of these numbers as doubles using the Math.Pow method for the payments and got incorrect calculations. I am assuming that the rate NEEDS to be a decimal, so when i try them ALL as decimals, VS doesnt like the "^" method or the math.pow method. So my question is, how are you supposed to use decimals with exponents? For those that wish to see my current code please note that i am just trying to get the calculations finished before i start adding extra 'else' statements.
decimal amnt = Convert.ToDecimal(txtAMNT.Text);
string Amount=Convert.ToString(txtAMNT.Text);
decimal rate = Convert.ToDecimal(txtRATE.Text);
string Rate = Convert.ToString(txtRATE.Text);
decimal time = Convert.ToDecimal(txtTIME.Text);
string Time=Convert.ToString(txtTIME.Text);
decimal monthpay;
decimal totalinterest;
decimal realrate = rate / 100;
if ((Amount == "")||(Rate == "")||(Time==""))
{
MessageBox.Show("Please fill all boxes with numbers");
}
else
{
monthpay=amnt*realrate/(1-(1+realrate)^(-time));
totalinterest=time*monthpay-amnt;
mtbMonPay.Text=monthpay.ToString("c");
mtbTotalInterest.Text=totalinterest.ToString("c");
}