I'm new to functions so I'm not sure where I'm going wrong with this. It's supposed to display all perfect numbers from 1 to 10000, but instead it displays every number from 1 to 10000.
A perfect number is an
integer p>1 such that the sum of the positive divisors of p equals p. For ex-
ample, 6 is a perfect number since 1+2+3 = 6; 28 is a perfect number since
1+2+4+7+14 = 28.
Write a complete C++ program to write to the file perfect.out all perfect numbers between 1 and a specified named integer constant LIMIT. For the purposes
of the assignment, set the value of LIMIT to 10000.
The program is to define and use the following two functions:
int sum_of_positive_divisors(int number)
that calculates and returns the sum of all positive divisors of the integer ar-
gument number; candidate divisors of number range from 1 to number / 2.
sum of positive divisors() will only be called by is perfect().
bool is_perfect(int number)
is a predicate (a boolean-valued function) that returns true i the integer argu-
ment number is a perfect number and false otherwise. is perfect() will call
sum of positive divisors(); is perfect() will only be called by main().
Your function wasn't returning the sum of positive divisors. Since you were using global variables, you could make it void and use the global variable to pass the value around, but that's a terrible use of globals and it makes the program harder to follow.