15,921,577 members
See more:
Hi i need some help
Whats the best method for this question:

Write a program to check whether a number input by the user is even or odd?

Here is what i have done so far (Not Much)

C#
```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AS15_Number_4
{
class Program
{
static void Main(string[] args)
{
Console.Write("Please Enter Me A Number : ");
int num1 = Convert.ToInt16(str);

}
}
}```

Posted
Pheonyx 5-Apr-13 5:25am
This sounds very much like homework. And from your namespace it looks like homework!
We are not here to do it for you.

I will ask you a simple question: forgetting computer code, how can you test if a number is odd or even?

## Solution 1

Hi,

Use the modulo operator %[^]:
C#
```if ((num1 % 2) == 0)
{
Console.WriteLine("even");
}
else
{
Console.WriteLine("odd");
}```

Hope this helps.

v2

## Solution 2

Hi,

Though I am providing you with the solution.Please google for such simple stuff.

C#
```using System;

using System.Collections.Generic;

using System.Text;

namespace OddEven

{

class OddOREven

{

{

n = 0;

try

{

n = Convert.ToInt32(input);

return true;

}

catch (System.Exception ex)

{

System.Console.WriteLine("Error in the input format\n\n");

return false;

}

}

static void Main(string[] args)

{

System.Console.Write("Enter a Number to Check ODD or EVEN: ");

int number = 0;

if((number % 2) == 0)

System.Console.WriteLine("{0} is an EVEN number", number);

else

System.Console.WriteLine("{0} is an ODD number", number);

}

}

}```

## Solution 3

You can check if a number is even by:

C#
`bool isEven = (number % 2) == 0`

or for odd:
C#
`bool isOdd = (number % 2) == 1`

and for zero:
C#
`bool isZero = (number == 0);`

you can also combine that to:
C#
```var result = number==0 ? "zero" : number%2 == 0 ? "even" : "odd";
Console.WriteLine(result);```

(if you don't know "?:" --> Ternary Operation[^])