- #1

- 48

- 4

What I am looking for is how to write a function which

__determines__whether a parameter

*number*is a perfect-number. Take the code below for example, notice how the function

*perfect*doesn't actually tell you whether

*number*is a perfect-number or not. All it does is add all the divisors of

*number*and put it into

*sum*. The part of the code that actually

__determines__whether

*number*is a perfect-number or not is inside the function

*main*.

In other words, I am wanting to know how to put the actual

__determination__(starting with...

**if(re==n)**...) inside the function

*perfect*, which I'm strugging with since my knowledge of function is that they end with

*return {expression}*(if they do indeed return a value), or simply

*return;*(if they don't return anything at all).

Code:

```
#include<iostream>
using namespace std;
int perfect(int number)
{
int sum=0;
for(int i=1;i<number;i++)
{
if(number%i==0)
{
sum=sum+i;
}
}
return sum;
}
void main()
{
int n;
cout<<"Enter a number: ";
cin>>n;
int re= perfect(n);
if(re==n)
cout<<"\n\nYes!\n It Is A perfect number.\n\n";
else
cout<<"\n\nNo! \n It Is Not A Perfect Number.\n\n";
}
```