title: magic square program help C#
body: <p>I need help debugging and finishing a program that would: read a file with same number of lines and same number of integer values on each line (this will be a n x n matrix). The program should determines if the matrix is a magic square.
  example of magic square: "ms.txt"
  8,1,6;3,5,7;4,9,2 </p>
  
  <p>my code (working in progress), your help would be appreciated </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.IO;
  
  namespace MagicSquare
  {
  class Program
  {
      static void Main(string[] args)
      {
          int[,]S;
          string line; //to hold one line of file
          string[] token; //to hold each token in line
          char[] separator = { ',' };
          int N;
  
          //open file
          try
          {
              using (StreamReader sr = new StreamReader("..\\..\\ms.txt"))
              {
                  line = sr.ReadLine();
                  token = line.Split(separator);
                  N = token.Count();
                  S = new int[N, N];
                  for (int i = 0; i &lt; N; i++)
                      S[0, i] = Convert.ToInt32(token[i]);
                  for (int r = 1; r &lt; N; r++)
                  {
                      line = sr.ReadLine();
                      token = line.Split(separator);
                      for (int c = 0; c &lt; N; c++)
                          S[r, c] = Convert.ToInt32(token[c]);
                  }
                  sr.Close();
              }
          }
          catch (Exception e)
          {
              Console.WriteLine("The file could not be read:");
              Console.WriteLine(e.Message);
          }
  
          //find Magic Number
         int magic = 0;
          for (int i = 0; i &lt; N; i++)
              magic += S[i, i];
          int sum = 0;
          for (int i=0;i&lt;N;i++)
              sum += S[i,N -1-i];
          if (magic!=sum)
          {
              Console.Write("Not Magic");
              return;
          }
          //check each column
          for (int c=0;c&lt;N;c++)
          {
              int sum1 =0;
              for (int r=0;r&lt;N;r++)
                  sum1 += S[r,c];
              if (sum1!=magic)
              {
                  Console.WriteLine("Not magic");
                  return;
              }
          }
      }
  }
  }
  </code></pre>