Monday, March 17, 2014

Mod Function_Ex_1 (Wk-4), Jan 27-31, 2014

Question: Checking for even or odd.
Request an integer value from user and display whether the number is odd or even

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

namespace Mod_Function_Ex_1
{
    class Program
    {
        static void Main(string[] args)
        {
            repeat:
            Console.Write("Enter an integer value: ");
            int userInput = int.Parse(Console.ReadLine());

            userInput = userInput % 2;
            if (userInput == 0)
            {
                Console.WriteLine("\nYour value is Even");
            }
            else
            {
                Console.WriteLine("\nYour value is Odd");
            }
            Console.WriteLine("\nHit enter to continue");
            Console.ReadLine();
            Console.Clear();
            goto repeat;
        }
    }
}

No comments:

Post a Comment