Simple, Quality, Awesome Software

Even and Odd

Below is the complete code for the Even and Odd Try It Out! problem.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EvenAndOdd
{
    class Program
    {
        static void Main(string[] args)
        {
            // Prompt the user to enter a value, get their input and convert it
            // from a string to an int.
            Console.Write("Enter a number: ");
            string input = Console.ReadLine();
            int number = Convert.ToInt32(input);

            // Determine the remainder
            int remainder = number % 2;

            // Print out whether it is even or odd. A remainder of 0 means it is
            // divisible by the value used with the % operator. When that value
            // is 2, it means it is divisible by two--even. Otherwise it is
            // an odd number.
            if (remainder == 0)
            {
                Console.WriteLine(number + " is even.");
            }
            else
            {
                Console.WriteLine(number + " is odd.");
            }

            // Wait for the user to respond before closing...
            Console.ReadKey();
        }
    }
}