Here is my program, which aims to show whether the input integer is a perfect number or not. It is required to use Boolean function and call it back in main function. However, after running the trial, there is no output. Can anyone help out this programming newbie...Thanks in advance for any help.
#include <iostream>
using namespace std;
bool perfect ( int num )
{
int sum = 0, i = 1;
while( i < num ) {
if ( num % i == 0 ) {
sum = sum + i;
i++;
}
}
if ( num == sum )
return 1 ;
else
return 0 ;
}
int main()
{
int num ;
cin >> num ;
if ( perfect ( num ) == 1 )
cout << " YES " << endl ;
else
cout << " NO " << endl ;
}