MortgageCalculator.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MortgageCalculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
CalculateTheMortgage();
}
private void CalculateTheMortgage()
{
// (Loan Value) * (1 + r/12) ^ p = (12x / r) * ((1 + r/12)^p - 1)
// payment = (((Loan Value) * (1 + r/12) ^ p) * r)/ (12 * ((1 + r/12)^p - 1)));
double loanAmount = (double)txtLoanAmount.CurrentValue; // price of total mortgage before down payment
double taxesPerYear = (double)txtPropertyTax.CurrentValue; // this will divided by 12 and added to the monthly payment
double downPayment = (double)txtDownPayment.CurrentValue; // down payment will be subtracted from the loan
double interestRate = (double)udInterest.Value / 100; // calculate interest from 100%
double termOfLoan = (double)(udTerm.Value * 12); // monthly term
double propertyTax = (double)txtPropertyTax.CurrentValue;
double insurance = (double)txtInsurance.CurrentValue;
double payment = (loanAmount - downPayment) * (Math.Pow((1 + interestRate/12), termOfLoan) * interestRate)/(12 * (Math.Pow((1+interestRate/12), termOfLoan) - 1));
// add on a monthly property tax
payment = payment + (propertyTax + insurance) / 12;
txtPayment.CurrentValue = (int)payment;
}
}
}
Comments
2 Responses to “MortgageCalculator.cs”
Thanks for the informative post.. and thanks for adding our comment to the blog. I am subscribing to your feed so I don\’t miss the next post!