public string InterestRate;
public double Payment { get; set; }
public double Cost { get; set; }
public double Interest { get; set; }
public Mortgage(string P, string ir, string n, double cp, double c, double i)
public double CalcPayment()
int iLoanAmt = Convert.ToInt32(LoanAmt);
double dblInterestRate = (Convert.ToDouble(InterestRate)/12);
int iLoanTerms = Convert.ToInt32(LoanTerms);
Payment = iLoanAmt *(dblInterestRate * Math.Pow((1+dblInterestRate),iLoanTerms) / (Math.Pow((1+dblInterestRate),iLoanTerms) - 1));
public double CalcTotalCost()
int iLoanTerms = Convert.ToInt32(LoanTerms);
Cost = Payment * iLoanTerms;
public double CalcInterest()
Interest = Cost - Payment;
public string ToStrings()
int[] colW = new int[3] {4, 10, 8};
string gap = "".PadRight(10);
string gap2 = "".PadRight(15);
"Monthly Payment".PadLeft(colW[0]) + gap +
"Total Cost".PadLeft(colW[1]) + gap +
"Total Interest".PadLeft(colW[2]));
"".PadRight(colW[0], '-') + gap2 +
"".PadRight(colW[1], '-') + gap2 +
"".PadRight(colW[2], '-')
Payment.ToString("C").PadLeft(colW[0]) + gap +
Cost.ToString("C").PadLeft(colW[1]) + gap +
Interest.ToString("C").PadLeft(colW[2])
while(counter1<=threshold1);
public static void Main (string[] args)
double dblPresentValue1 = 0.0;
double dblPresentValue2 = 0.0;
double dblPresentValue3 = 0.0;
Mortgage mortgage = new Mortgage();
Console.Write("Enter princial loan amount= ");
LoanAmt = Console.ReadLine();
if (!double.TryParse(LoanAmt, out dblPresentValue1) || dblPresentValue1 <= 0)
Console.WriteLine("Princial Loan Amount must be positive number!");
Console.Write("Enter annual interest rate (as percentage)= ");
InterestRate = Console.ReadLine();
if (!double.TryParse(InterestRate, out dblPresentValue2) || dblPresentValue2 <= 0)
Console.WriteLine("Rate must be positive number!");
Console.Write("Enter monthly term of loan= ");
LoanTerms = Console.ReadLine();
if (!double.TryParse(LoanTerms, out dblPresentValue3) || dblPresentValue3 <= 0)
Console.WriteLine("Term must be positive number!");
while (counter2<=threshold2);
mortgage.LoanAmt = LoanAmt;
mortgage.InterestRate = InterestRate;
mortgage.LoanTerms = LoanTerms;
Console.WriteLine(mortgage.CalcPayment());
Console.WriteLine(mortgage.CalcTotalCost());
Console.WriteLine(mortgage.CalcInterest());
Console.WriteLine(mortgage.ToStrings());
while (counter<=threshold);