Can't figure out what I am doing wrong here to get my output to look like the example. I've attached the example output + what output I get. I don't have any bugs or errors I can find but is it something I did wrong with my loop? I'm fairly inexperienced with programming so apologies if this is a simple mistake.
private double CalcPayment(double principal, double rate, int term)
{
double payment = (principal * rate) / (1 - (Math.Pow(rate + 1, -term)));
return payment;
}
private void btnCalc_Click(object sender, EventArgs e)
{
//Input
double principal = Convert.ToDouble(txtPrincipal.Text);
double rate = Convert.ToDouble(txtRate.Text);
int term = Convert.ToInt32(txtTerm.Text);
//Processing
rate /= 100;
double balance = principal;
double annualPayment = CalcPayment(principal, rate, term);
rtbOut.Text = "Village of Muddy Bottom".PadLeft(15) + "\n" + "Bond Payment Schedule".PadLeft(16) + "\n";
int yearsCounter;
double annualInterest;
double principalPaid;
double totalInterest = 0;
for (yearsCounter = 1; yearsCounter <= term; yearsCounter++)
{
annualInterest = balance * rate;
principalPaid = annualPayment - annualInterest;
balance -= principalPaid;
totalInterest += annualInterest;
rtbOut.Text = term.ToString().PadLeft(5) + balance.ToString("c").PadLeft(20) + annualInterest.ToString("c").PadLeft(30) + principalPaid.ToString("c").PadLeft(40) + "\n";
}
//Postprocessing/Output
rtbOut.Text = "Total" + totalInterest.ToString("c").PadLeft(40);
lblPayment.Text = annualPayment.ToString("c");
}