title: C# Output max min average array using a text file?
body: <p>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). </p>
  
  <p>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. </p>
  
  <p>I've watched some videos and found similar problems listed on this site but am stuck :(. Can anyone help? </p>
  
  <p>Program code is: </p>
  
  <pre><code>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 &lt; 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 &lt; hoursArray.Length; index++)
              {
                  Console.WriteLine(hoursArray[index]);
              }
              Console.ReadKey();
  
              int total = 0;      
              double average = 0; 
              for (int index = 0; index &lt; 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 &lt; hoursArray.Length; index++)
              {
                  if (hoursArray[index] &gt; high)
                  {
                      high = hoursArray[index];
                  }
              }
  
              Console.WriteLine("Highest number = " + high);
  
  
              int low = hoursArray[0];   
  
              for (int index = 0; index &lt; hoursArray.Length; index++)
              {
                  if (hoursArray[index] &lt; low)
                  {
                      low = hoursArray[index];
                  }
              }
  
              Console.WriteLine("Lowest number = " + low);
              Console.ReadKey();
  
          }
      }
  }
  </code></pre>
  
  <p>The numbers in the Values.txt looks like this: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>I understand the problem, I just do not know how to fix it!</p>