How can I get the results to show each year and the year end value for each year?
double investment_decimal = Double.Parse(txtAmount.Text);
double rate_decimal = Double.Parse(txtRate.Text);
double years = Double.Parse(txtSlideValue.Text);
years = Convert.ToDouble(txtSlideValue.Text);
double calculation = 0;
//for loop
for (int i = 1; i < years + 1 ; i++)
{
calculation = investment_decimal * Math.Pow((1 + rate_decimal / years), (i));
txtCalculation.Text = Convert.ToString("Year " + i.ToString() +"\t" + "Year End Value " + calculation.ToString("C")).PadRight(10);
}
yearsis 5. You will go through that loop 5 times, and each time you will reset the value ofcalculationandtxtCalculationto whatever it is on that iteration. If you want to output the values from each iteration, you either need to store the values in a variable collection (list, array, etc), or add the values onto the end of your variables (calculation = calculation + etc)