Esempio n. 1
0
        static void Main()
        {
            //Main program
            string[] ContinueOptions = new string[] { "Y", "N" };
            bool     ContinueProgram = true;

            while (ContinueProgram)
            {
                bool   FileNameValid = false;
                string FileName      = "";
                while (!FileNameValid)
                {
                    System.Console.Write("Enter a filename: ");
                    FileName = System.Console.ReadLine();
                    if (FileHandler.FileExists(FileName))
                    {
                        break;
                    }
                    System.Console.WriteLine("Invalid filename");
                }
                string[] FileContents = FileHandler.ReadFileToArray(FileName);
                double[] Values       = new double[0];
                //For every line from the file, check it is a double and if so, expand the double array and put it in
                foreach (string Line in FileContents)
                {
                    if (IsDouble(Line))
                    {
                        System.Array.Resize <double>(ref Values, Values.Length + 1);
                        Values[Values.Length - 1] = double.Parse(Line);
                    }
                }
                string Output = "No usable data";
                //Only work on arrays with something in
                if (Values.Length > 0)
                {
                    Output = "-----" + FileName + "-----\n\n" + "Mean: " + StatsCalculator.CalculateMean(Values).ToString() + "\nStandard Deivation: " +
                             StatsCalculator.CalculateStdDev(Values).ToString() + "\nStandard Error: " + StatsCalculator.CalculateStdErr(Values).ToString();
                }
                System.Console.WriteLine(Output);
                string ContinueChoice = TakeStringInput(ContinueOptions, "Restart program? (Y/N): ");
                if (ContinueChoice.ToLower() == "n")
                {
                    ContinueProgram = true;
                }
                System.Console.Clear();
            }
        }