Пример #1
0
 /// <summary>
 /// Below the multiplication table method validates the input making sure what
 /// is put in is not null, and that it can be converted to an int then it takes the iput and
 /// runs it in a nested for loop that does the multiplication
 /// </summary>
 internal static void MultiplicationTables()
 {
     //Validates the input and ensures that it is an int.
     #region ValidateInput and make sure it is an Int
     while (string.IsNullOrWhiteSpace(userInput))
     {
         Console.WriteLine("Please Enter an Integer you would like see Muliplication Tables for");
         userInput = Console.ReadLine();
     }
     //try catch block that checks whether the input is valid by attempting to convert it to an int
     try
     {
         numCheck = Convert.ToInt32(userInput);
     }
     // catch format exception when the user types anything other than an int
     catch (FormatException e)
     {
         Console.WriteLine(userInput + " is not a valid integer", e);
         userInput = null;
         MultiplicationTables();
     }
     #endregion
     /// for loop that runs for every number lower than or equal to the user input number
     /// it then takes the local variables computes a multiplication for them and prints out the
     /// results with the console writeline
     for (int i = 1; i <= numCheck; i++)
     {
         for (int j = 0; j <= numCheck; j++)
         {
             Console.WriteLine("{0}x{1} = {2}", i, j, i * j);
         }
     }
     //run app again to go back to main menu
     RunApplication.RunApp();
 }
 /// <summary>
 /// Validate that the user input information is not empty
 /// accept input from the user and assign the correlating arrays
 /// combine the arrays at the indexes into a list that alternates between each list
 /// </summary>
 internal void ShuffleInfo()
 {
     // Do- while runs while the each lists is less than the target number
     // does this for each list until each list is full of the customer provided input
     #region Validate that input is not null and add input to first list
     do
     {
         userInput = null;
         while (string.IsNullOrWhiteSpace(userInput))
         {
             Console.WriteLine("Enter an item for the first list \n List item number : " + listOneItems);
             userInput             = Console.ReadLine();
             listOne[listOneItems] = userInput;
             listOneItems++;
             Console.Clear();
         }
     } while (listOneItems <= 4);
     #endregion
     #region Validate that input is not null and add input to Second list
     do
     {
         userInput = null;
         while (string.IsNullOrWhiteSpace(userInput))
         {
             Console.WriteLine("Enter an item for the Second list\n List item number :" + listTwoItems);
             userInput             = Console.ReadLine();
             listTwo[listTwoItems] = userInput;
             listTwoItems++;
             Console.Clear();
         }
     } while (listTwoItems <= 4);
     #endregion
     // run a for loop that adds the list one item at the index to the combined
     //list and the list 2 item at that same index, this will alternate the results
     for (int i = 0; i < listOne.Length; i++)
     {
         combinedList.Add(listOne[i]);
         combinedList.Add(listTwo[i]);
     }
     // For each loop to read out each item saved in the combined list
     foreach (string listItem in combinedList)
     {
         Console.WriteLine(listItem);
     }
     //run application again to start it all over
     RunApplication.RunApp();
 }
        /// <summary>
        /// Is even checks to see if the number input is divisable by 2 and
        /// therefore even after trying to covert the userInput to int, if
        /// it can't convert the user input to int it will catch a format exception
        /// </summary>
        internal static void IsEven()
        {
            ConsoleKeyInfo esc;

            Console.WriteLine("Press the Escape (Esc) at any time to quit: \n");
            #region Validate Input
            // while check to make sure the user didn't put nothing
            while (string.IsNullOrWhiteSpace(userInput))
            {
                Console.WriteLine("Please Enter an Integer you would like to check");
                userInput = Console.ReadLine();
            }
            //try catch block that checks whether the input is valid by attempting to convert it to an int
            try
            {
                numCheck = Convert.ToInt32(userInput);
            }
            // catch format exception when the user types anything other than an int
            catch (FormatException e)
            {
                Console.WriteLine(userInput + " is not a valid integer", e);
                userInput = null;
                IsEven();
            }
            #endregion
            #region Check Results
            // check to see if the number is divisable by 2
            if (numCheck % 2 == 0)
            {
                Console.WriteLine(userInput + " is Even");
                userInput = null;
            }
            // if it is not divisable by 2 notify the user
            else
            {
                Console.WriteLine(userInput + " is not Even");
                userInput = null;
            }
            #endregion
            // run applicaiton from the main menu again since this task has been completed.
            RunApplication.RunApp();
        }
 static void Main(string[] args)
 {
     RunApplication.RunApp();
 }