Hi,
Im new at C# programming....just practicing some programming concepts. I was working on a array program...when I encountered this error message: "Use of unassgined local variable 'avg'". I had already declared this variable previously. So Im not sure how to fix this error.
using System;
namespace ConsoleApplication1
{
class Array2
{
public static void Main()
{
int[] nums = new int[5];
nums[0] = 69;
nums[1] = 95;
nums[2] = 76;
nums[3] = 85;
nums[4] = 100;
int avg;
for (int i = 0; i < 5; i++)
{
avg = nums;
}
avg = avg / 10;//here is where the problem occurs
Console.WriteLine("Average: {0}", avg);
}
}
}
Im new at C# programming....just practicing some programming concepts. I was working on a array program...when I encountered this error message: "Use of unassgined local variable 'avg'". I had already declared this variable previously. So Im not sure how to fix this error.
using System;
namespace ConsoleApplication1
{
class Array2
{
public static void Main()
{
int[] nums = new int[5];
nums[0] = 69;
nums[1] = 95;
nums[2] = 76;
nums[3] = 85;
nums[4] = 100;
int avg;
for (int i = 0; i < 5; i++)
{
avg = nums;
}
avg = avg / 10;//here is where the problem occurs
Console.WriteLine("Average: {0}", avg);
}
}
}