I just need little help with this Amortization Calculator. The only problem with this is that when you change any of the numbers (loan amount, rate, term) and then hit calculate again, it calculates everything but it doesn't clear the previous data. It keeps adding to the last one.
I've attached screenshots. I don't know how to fix that. Can someone help me out please? I've attached zip file, and two screenshots.
http://img834.imageshack.us/img834/6480/55165440.png
http://img268.imageshack.us/img268/5392/82416026.png
Suthish NairPosted Feb 1, 2011, 12:48 PM
Query resolved?
Blocked AccountPosted Jan 31, 2011, 11:26 PM
I have added one line in your btncalculate_Click method and it works fine as you want.
private void btncalculate_Click(object sender, EventArgs e)
{
txtresults.Text = "";
// This is converting all three inputs into double types.
double loanAmount = Convert.ToDouble(txtloanamt.Text); // Converting loanamount into double types.
double rate = Convert.ToDouble(txtrate.Text) / 100; // Converts interest rate into double types.
double numPayments = Convert.ToDouble(txtterm.Text); // Converts Loan terms into integer.
// Calculate monthly payment.
double payment = loanAmount * (Math.Pow((1 + rate / 12), numPayments) * rate) / (12 * (Math.Pow((1 + rate / 12), numPayments) - 1));
// show this monthly payment in textbox.
txtpayment.Text = payment.ToString("C");
double interestRateMonth;
double totalPrincipalPaid = 0;
for (Int16 intMonth = 1; intMonth < 13; intMonth++)
{
loanAmount -= totalPrincipalPaid;
interestRateMonth = (rate / 12) * loanAmount; //Calculates monthly interest
totalPrincipalPaid = (payment - interestRateMonth);
txtresults.Text += "Month ";
txtresults.Text += Convert.ToInt16(intMonth);
txtresults.Text += "\t";
txtresults.Text += "Interest: ";
txtresults.Text += interestRateMonth.ToString("C");
txtresults.Text += "\t";
txtresults.Text += "Principal: ";
txtresults.Text += totalPrincipalPaid.ToString("C");
txtresults.Text += Environment.NewLine;
} //close displaying table.
} // close Submit button calculations
Suthish NairPosted Jan 31, 2011, 2:03 PM