Convert the following program to use methods

Mar 4 2023 11:15 AM

Convert the following program to use methods

static void Main(string[] args) 
{
    Console.Write("Enter a value ");
    int value = int.Parse(Console.ReadLine());
    if (value % 2 == 0)
    {
        Console.WriteLine($"{value} is even");
    }
    else
    {
        Console.WriteLine($"{value} is odd");
    }
    Console.Write("Enter a value ");
    value = int.Parse(Console.ReadLine());
    if (value % 2 == 0)
    {
        Console.WriteLine($"{value} is even");
    }
    else
    {
        Console.WriteLine($"{value} is odd");
    }
    Console.Write("Enter a value ");
    value = int.Parse(Console.ReadLine());
    if (value % 2 == 0)
    {
        Console.WriteLine($"{value} is even");
    }
    else
    {
        Console.WriteLine($"{value} is odd");
    }
}

To be like this:

static void Main(string[] args) 
{
    int value = RequestValue();
    bool isEven = IsEven(value);
    PrintResult(isEven, value);
    value = RequestValue();
    isEven = IsEven(value);
    PrintResult(isEven, value);
    value = RequestValue();
    isEven = IsEven(value);
    PrintResult(isEven, value);
    Console.ReadLine();
}

 


Answers (2)