Where to declare variable? C#

Posted by user1303781 on Stack Overflow See other posts from Stack Overflow or by user1303781
Published on 2012-03-30T17:04:12Z Indexed on 2012/03/30 17:29 UTC
Read the original article Hit count: 121

Filed under:
|

I am trying to make an average function... 'Total' adds them, then 'Total' is divided by n, the number of entries...

No matter where I put 'double Total;', I get an error message. In this example I get... Use of unassigned local variable 'Total'

If I put it before the comment, both references show up as error... I'm sure it's something simple.....

namespace frmAssignment3
{
    class StatisticalFunctions
    {

        public static class Statistics
        {

            //public static double Average(List<MachineData.MachineRecord> argMachineDataList)
            public static double Average(List<double> argMachineDataList)
            {
                double Total;

                int n;
                for (n = 1; n <= argMachineDataList.Count; n++)
                {
                    Total = argMachineDataList[n];
                }

                return Total / n;
            }

            public static double StDevSample(List<MachineData.MachineRecord> argMachineDataList)
            {

                return -1;
            }
        }

    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about homework