I know this is the tutorial section but I think it'd be nice to give some feedback about that code.
Your indentation is a bit inconsistent in places. This may well be because of the forum and perhaps you are using a text editor or IDE that formats things in a different way, but the whole main() function needs some indentation and the isPerfectNumber() function needs to be more consistent - the comments being more indented than the code itself makes them much harder to read.
Some variable names like "potentialPerfectNumber" and "totalValue" are quite long. I'd just simply name them "num" and "total" or "sum".
In many ways you've commented too much.
Comments, in my opinion, should add something to the code rather than state what the code means a second time. For example:
Code:
// declares the sum variable and sets it to zero
int sum = 0;
is a useless comment whereas this:
Code:
// stores the sum of all the factors
int sum = 0;
actually adds to the code rather than repeating it in human form.
If you took all/some of this advice, your isPerfectNumber method would look more like this which in my opinion is much more elegant even though none of the logic changed:
Code:
// A function to check if the specified number is perfect. A perfect number is
// a positive integer that is the sum of all of its factors.
bool is_perfect(int num)
{
// If the number is zero or negative it is not perfect.
if (num <= 0)
return false;
// Stores the sum of all the factors.
int sum = 0;
// Loops through all the factors of the number and adds them to the sum.
for (int factor = 1; factor <= (num / 2); factor++)
if (num % factor == 0)
sum += factor;
// If the number equals the sum of its factors it is perfect.
return num == sum;
}