#include <iostream>
#include <iomanip>
usingnamespace std;
int main(){
//Write a program that asks the user for input for two integer values: startval, and endval. The program will then find all Perfect Numbers that fall between startval and endval.
//A perfect number is a number equal to the sum of all its proper divisors (divisors smaller than the number) including 1.
//The number 6 is the smallest perfect number; because it is the sum of its divisors 1, 2, and 3 (1+2+3 = 6). The next perfect number is 28 (28 = 1+2+4+7+14).
int startVal, endVal, num = 0, inNum, possibleNum, sum;
cout << "Enter starting integer : ";
cin >> startVal;
cout << "Enter ending integer : ";
cin >> endVal;
for(num = startVal ; num <= endVal ; num++){
sum =0;
for(inNum = 1 ; inNum < num ; inNum++){
if(isAFactor(num, inNum))
sum = sum + inNum;
}
if(sum == num){
cout << num << " is a perfect number." << endl;
}
}
}
bool isAFactor (int num1,int num2){
int numA = num1;
int numB = num2;
if(numA % numB == 0)
returntrue;
elsereturnfalse;
}
This is kind of right. You don't want to move it to main (whether that be top, bottom or somewhere in between). You want to put it before main (I'm pretty sure that that is what you meant, but it seemed a little vague and easily misunderstood).