Esempio n. 1
0
        public static void Main()
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            TypeLine("Welcome to the Word Counter program");
            string        inputWord = GetWord();
            RepeatCounter newCount  = new RepeatCounter();
            bool          wordValid = newCount.ValidateWord(inputWord);
            bool          realWord  = newCount.DictionaryCheck(inputWord);

            // if the filepath for the dictionary text file is not working properly, the program will exit after you enter the first word.  to bypass this, comment out line 16 and use the bool value for realWord from line 18 instead
            // bool realWord = true;
            if (wordValid)
            {
                if (!realWord)
                {
                    DoesntExist();
                }
                string inputSent = GetSentence();
                bool   sentValid = newCount.ValidateSentence(inputSent);
                if (sentValid)
                {
                    int result = newCount.CountWords();
                    Console.Clear();
                    Console.Write(Environment.NewLine);
                    if (result == 1)
                    {
                        TypeLine("The word '" + newCount.RootWord + "' appears in the sentence you entered only " + result + " time. Yay!");
                        PlayAgain();
                    }
                    else
                    {
                        TypeLine("The word '" + newCount.RootWord + "' appears in the sentence you entered " + result + " times. Yay!");
                        PlayAgain();
                    }
                }
                else if (!sentValid)
                {
                    ErrorMessage("sentence");
                }
            }
            else
            {
                ErrorMessage("word");
            }
        }