The idea is to sum the proper divisors of n. Here is a pre-simulation of that for n = 6.
n i sum i a proper divisor of n?
6 1 1 yes
2 3 yes
3 6 yes
4 6 no
5 6 no
Here is a pre-simulation for n = 8.
n i sum i a proper divisor of n?
8 1 1 yes
2 3 yes
3 3 no
4 7 yes
5 7 no
6 7 no
7 7 no
Here is a definition of isPerfect based on those pre-simulations.
bool isPerfect(const int n)
{
int sum = 1;
int i = 1;
while(i < n)
{
i++;
if(n % i == 0)
{
sum = sum + i;
}
}
}
return (sum == n);