I had done a previous exercise whereby I had to write a program where a user would input 30 different numbers (hours) and the program would spit out the array, average, min, and max. That was fine. Now, however, I am tasked with reading the numbers from a text file (and outputting the same as before - array, avg, min, max).
I am hitting an error based on the original exercise, where I am told that a name does not exist in the program (I understand this is because the text doc now holds that previous name). I don't know what I need to do to change this.
I've watched some videos and found similar problems listed on this site but am stuck :(. Can anyone help?
Program code is:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace IntsArray
{
class Program
{
static void Main(string[] args)
{
StreamReader myReader = new StreamReader("Values.txt");
string line = "";
while (line != null)
{
line = myReader.ReadLine();
if (line != null)
Console.WriteLine(line);
}
myReader.Close();
Console.ReadLine();
for (int index = 0; index < hoursArray.Length; index++)
{
Console.Write("Enter your hours: ");
hoursArray[index] = int.Parse(Console.ReadLine());
}
Console.WriteLine("Numbers in the list: " + hoursArray.Length);
for (int index = 0; index < hoursArray.Length; index++)
{
Console.WriteLine(hoursArray[index]);
}
Console.ReadKey();
int total = 0;
double average = 0;
for (int index = 0; index < hoursArray.Length; index++)
{
total = total + hoursArray[index];
}
average = (double)total / hoursArray.Length;
Console.WriteLine("Average = " + average.ToString("N2"));
int high = hoursArray[0];
for (int index = 1; index < hoursArray.Length; index++)
{
if (hoursArray[index] > high)
{
high = hoursArray[index];
}
}
Console.WriteLine("Highest number = " + high);
int low = hoursArray[0];
for (int index = 0; index < hoursArray.Length; index++)
{
if (hoursArray[index] < low)
{
low = hoursArray[index];
}
}
Console.WriteLine("Lowest number = " + low);
Console.ReadKey();
}
}
}
The numbers in the Values.txt looks like this:
8
24
9
7
6
12
10
11
23
1
2
9
8
8
9
7
9
15
6
1
7
6
12
10
11
23
1
2
9
8
I understand the problem, I just do not know how to fix it!

hoursArray, where is it declared?while ((line = sr.ReadLine()) != null)