Another problem is this piece of code:

Shining Arcanine wrote:

    if (x = 0)
    {
        return 0;
    }

Here, you're evaluating the value of x after setting it to 0. This has two implications:
  1. The code inside the if-block will never be executed, since (x = 0) evaluates to the value of x, which is 0 after the assignment.
  2. x will always be 0 below the block.

What you want to say is:

if(x == 0)
{
  return 0;
}