//File: Demarco_1_1
//Author: Jesse Demarco
//Date: Feb. 12, 2007
//
//Description: This program prompts the user to enter a positive number.
// This number is passed to a function wich checks if it is perfect.
// A loop decrements the inputed value, and once again calls the funtion
// until all values from the input number down to 6 have been checked.
// because six is the smallest perfect number, it is the last number to be
// checked.
#include <iostream>
#include <cmath>
using namespace std;
void findPerfectNumber(int a, int b, int c){
a-=1;
if ((b % a) == 0){
c +=a;}
if ((a > 0) && ((c) == b)&& (a == 1)){
cout << c << " is a perfect number " << endl;
}
if (a > 1){
findPerfectNumber(a, b, c);
}
}
int main()
{
int factors;
int nPerfect = 0;
int j = 0;
cout << "Enter an integer to be tested ";
cin >> nPerfect;
cout << endl;
j = nPerfect;
for (j = nPerfect; j > 1; ){
findPerfectNumber(j, j, 0);
--j;
}
return 0;
}