BLOG.CSHARPHELPER.COM: Calculate the future value of a monthly investment with interest in C#
Calculate the future value of a monthly investment with interest in C#
The magic of compound interest is that, over time, you get interest on the interest
For each month the program calculates the interest on the account balance. It then adds the interest and a monthly contribution to the balance and displays the result. (Note that interest is compounded monthly not continuously.)
The following code shows how the program performs its calculations.
// Calculate the interest compounded monthly. private void btnGo_Click(object sender, EventArgs e) { // Get the parameters. decimal monthly_contribution = decimal.Parse( txtMonthlyContribution.Text, NumberStyles.Any); int num_months = int.Parse(txtNumMonths.Text); decimal interest_rate = decimal.Parse( txtInterestRate.Text.Replace("%", "")) / 100; interest_rate /= 12;
// Calculate. lvwBalance.Items.Clear(); decimal balance = 0; for (int i = 1; i <= num_months; i++) { // Display the month. ListViewItem new_item = lvwBalance.Items.Add(i.ToString());
Comments