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()
        {
            InitializeComponent();
        }

        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");



                }

                listBox1.Items.Add(lineOutput);

            }

            rate.ToString("p");
        }
    }
}

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

//instead of:
double rate, year, presentValue, futureValue;
//do:
double rate = 0, year = 0, presentValue = 0, futureValue = 0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.