to anyone I am currently writing this C# program for a C# class I am taking and I
have the correct formula which is Future Value=PresentValue*(1=Rate)Year
the issue I am having is there is an error message for the futureValue= presentValue, the presentValue has the message Use of unassigned local variable 'presentValue'
and I did declare it in the beginning using double presentValue and its still giving me that message how do I fix this problem.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Future_Value_List_view
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            double rate, year, presentValue, futureValue;
            string lineOutput;
            listBox1.Items.Add("Rate/Year 5     10     15     20");
            for (rate = 0.03; rate <= .05; rate += .005)
                lineOutput = rate.ToString("p2");
                for (year = 5; year <=20; year +=5)
                    futureValue = presentValue * Math.Pow(1 + rate, year);
                    lineOutput = lineOutput + " " + futureValue.ToString("C");





Edited by Dani: Formatting fixed

6 Years
Discussion Span
Last Post by Mitja Bonca

When you instanitate new variables, specify their beggining values, like:

//instead of:
double rate, year, presentValue, futureValue;
double rate = 0, year = 0, presentValue = 0, futureValue = 0;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.