My IsPerfect function aint working and I dont no where i went wrong.

bool IsPerfect(int num)
{	
	int sum = 0;
	int x;
	int divisor;

	x = num;

	while(x > 0)
	{
		divisor = x;


		if(num % divisor == 0)
		{
			sum += divisor;
		}
		x--;
	}

	if(sum == num)
	{
		return true;
	}
	else
	{
		return false;
	}
}

In the first iteration of your while() loop, you divide the number by itself, which will always divide evenly, thus making your sum twice as large as it should be.