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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.