#include <iostream.h>

// Perfect Numbers Programming Problem
// Input: A positive integer
// Output: A message stating whether the number is perfect, abundant,
// or deficient.

// The program continues to prompt for input until a nonpositive integer 
// is provided as input.


// function header:
int sumdiv( int n );

int main()
{
  int n, s;
  while(1)
  {
    cout << endl << "Enter an integer (0 to quit): ";
    cin >> n;
    if( n < 1 ) break;

    s = sumdiv(n);
    if( s < n )
      cout << n << " is deficient." << endl;
    else if( s > n )
      cout << n << " is abundant." << endl;
    else
      cout << n << " is perfect." << endl;
  }
  cout << "Goodbye!" << endl;

  return 0;
}

// computes and returns the sum of the proper divisors of n
// (assumes n is positive)
// for example, if n=12, the return value is 1+2+3+4+6=16
int sumdiv( int n )
{
  int sum = 0;
  for( int i = 1; i <= n/2; i++ )
    if( n%i == 0 )
      sum += i;

  return sum;
}
