bool perf;
int sum = 0;
int k = 1;
while(k < n)
{
if(n % k == 0)
{
sum = sum + k;
}
k++;
}
perf = (sum == n);
Should we add a test to see whether 0 < k < n?
After all, the problem statement says that. The answer is no.
Since k starts at 1 and the loop body is only done when k < n,
asking whether 0 < k < n is redundant.