I am new to C++. This is a homework problem. So if anyone gives up their time to help me it is greatly appreciated. I have perfect number program, I can get it to run if all my code is in the main. The assignment requests that I use a function to check numbers to see if they are perfect. I am getting an error when I use the function. I checked MSDN to find some help to no avail. So here is the code. Thanks again for any help!:cheesy:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int perfect (int);
int main ()
{
int number = 1;
int perfect = 0;
for(number=1; number < 1000; number++)
{
perfect = perfect(number); //here is where I call the function
if (perfect > 0)
{
cout << perfect << " is a perfect number." << endl;
cout << "It's factors are: ";
for ( int y = 1; y < perfect/2; y++ )
{
int divisor = perfect / y;
if ( perfect % y == 0 && y <= divisor)
{
cout << divisor << " " << y << endl;
}
} // ends factor perfect
} // ends if perfect
} // ends for to 1000
}// ends main
int perfect (int counter) //here is where the function starts
{
int sum = 0;
int divisor = 0;
int y = 0;
for (y = 1; y < counter/2; y++)
{
divisor = counter / y;
if ( counter % y == 0 && y <= divisor)
{
int factors = y + divisor;
sum += factors;
}
}
if (sum - counter == counter)
{
return counter;
}
else
return 0;
}//ends function