1
Answer

How to set up a breakpoint to test month and futureValue?

Photo of camella Seals

camella Seals

7y
279
1
Hello Everyone,
 
I am trying to figure out what's the best way how I can set up a conditional expression using a breakpoint to determine the month and futureValue values in a for loop. I already set up the breakpoint, but I just don't know how I can set up conditions properly. In my web application, after I have set up the breakpoint, I show be able to see index (month) and futureValue of that month right? Here is my C# code and in it you will that the statement " futureValue= (futureValue )  .... " is the executable statement that I would like my breakpoint to be at.  
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7.   
  8. namespace XEx05FutureValue  
  9. {  
  10.     public partial class Default : System.Web.UI.Page  
  11.     {  
  12.         protected void Page_Load(object sender, EventArgs e)  
  13.         {  
  14.             if (!IsPostBack)  
  15.                 for (int i = 50; i <= 500; i += 50)  
  16.                     ddlMonthlyInvestment.Items.Add(i.ToString());  
  17.         }  
  18.   
  19.         protected void btnCalculate_Click(object sender, EventArgs e)  
  20.         {  
  21.             if (IsValid)  
  22.             {  
  23.                 int monthlyInvestment = Convert.ToInt32(ddlMonthlyInvestment.SelectedValue);  
  24.                 decimal yearlyInterestRate = Convert.ToDecimal(txtInterestRate.Text);  
  25.                 int years = Convert.ToInt32(txtYears.Text);  
  26.   
  27.                 decimal futureValue = this.CalculateFutureValue(monthlyInvestment,  
  28.                     yearlyInterestRate, years);  
  29.   
  30.                 lblFutureValue.Text = futureValue.ToString("c");  
  31.             }  
  32.         }  
  33.   
  34.         protected decimal CalculateFutureValue(int monthlyInvestment,  
  35.         decimal yearlyInterestRate, int years)  
  36.         {  
  37.             int months = years * 12;  
  38.             decimal monthlyInterestRate = yearlyInterestRate / 12 / 100;  
  39.             decimal futureValue = 0;  
  40.             for (int i = 0; i < months; i++)  
  41.             {  
  42.                 futureValue = (futureValue + monthlyInvestment)  
  43.                     * (1 + monthlyInterestRate);  
  44.             }  
  45.             return futureValue;  
  46.         }  
  47.   
  48.         protected void btnClear_Click(object sender, EventArgs e)  
  49.         {  
  50.             ddlMonthlyInvestment.SelectedIndex = 0;  
  51.             txtInterestRate.Text = "";  
  52.             txtYears.Text = "";  
  53.             lblFutureValue.Text = "";  
  54.         }  
  55.     }  
  56. }  

Answers (1)

0
Photo of Ankit Sharma
NA 8.8k 141k 7y
Hi Camella,
 
Put your breakpoint at line 36 and 41
 
once execution hits at line 36 then you can press F10 to execute step by step,you can get month value from here.
After one iteration of loop is compete,then move your cursor to  "futureValue" to see the value of that variable.