我需要知道为什么会收到错误消息“使用未分配的局部变量“ totalFee”。我真的很努力地理解这一点,我得到了基本的信息,我正在努力解决所有这些新错误。
{int[] hoursArray = new int[50];
const decimal HOURLY_RATE = 2.5M;
const decimal MAX_FEE = 20.00M;
decimal parkFee;
int counter = 0;
string line;
decimal totalFee, avFee;
StreamReader fileSR = new StreamReader("hours.txt");
//data for hours read from "hours.txt" file
line = fileSR.ReadLine();
while (line != null)
{
hoursArray[counter] = int.Parse(line);
counter = counter + 1;
line = fileSR.ReadLine();
}
for (int i = 0; i < hoursArray.Length; i++)
{
parkFee = hoursArray[i] * HOURLY_RATE;
if (parkFee > MAX_FEE)
{
parkFee = MAX_FEE;
}
fileSR.Close();
Console.ReadLine();
totalFee=totalFee + parkFee;
}
avFee = totalFee/hoursArray.Length;
Console.WriteLine("The average parking fee is " + avFee.ToString("N2"));
Console.ReadLine(); }