Calculate Mortgage in c# using console application
Formula : M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
- M = monthly mortgage payment
- P = the principal, or the initial amount you borrowed.
- i = your monthly interest rate. Your lender likely lists interest rates as an annual figure, so you’ll need to divide by 12, for each month of the year. So, if your rate is 5%, then the monthly rate will look like this: 0.05/12 = 0.004167.
- n = the number of payments, or the payment period in months. If you take out a 30-year fixed rate mortgage, this means: n = 30 years x 12 months per year, or 360 payments.
___________________________________ Start Code _________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Oops_Concepts
{
class Program
{
static void Main(string[] args)
{
Program objProgram = new Program();
objProgram.getMortgageCalculation();
Console.Read();
}
public void getMortgageCalculation()
{
double term = 30; //*30 years
double interestRate = 0.0575; //*5.75% interest rate
double principal = 200000; //*$200,000 Loan
double monthlyPayment;
monthlyPayment = (principal * interestRate * Math.Pow(1 + interestRate, term) / (Math.Pow(1 + interestRate, term)) - 1);
Console.WriteLine(monthlyPayment);
}
}
}
___________________________________ End Code _________________________________
Comments
Post a Comment