i'm taking a computer programming class, and i was given a chalange to create a program in "C++" that would tell you if the number you entered was a Perfect number, being that the sum of all the factors of a number minus itself would = the original number.
aka. 6 is perfect because 1+2+3+6 - 6 = 6... the factors of six are 1,2,3 & 6
8 is not because 1+2+4+8-8=7, so it is deficent... see where i'm going?
anyways i need a program to calculate the factors, and then compare them to the original number, i allready have part of it, i have a program that will calculate some of the factors, but not all of them,
#include <iostream>
using namespace std;
int FactCount(int nLoopCount);
int main()
{
int input;
cout << "Enter Number to be factored:\n";
cin >> input;
FactCount(input);
return 0;
}
int FactCount(int nLoopCount){
int nFirst;
if(nLoopCount > 1000000){
nLoopCount = 0;
cout << "Number to be factored must be less than 1000000:\n";
}
for (int j=2; j <= nLoopCount; j++){
for (int i=2; i <=nLoopCount; i++){
nFirst = j*i;
if(nFirst > 1000000)
break;
if(nFirst == nLoopCount){
cout << j <<" * "<< i <<" = "<< nFirst << " sum of factors = "<< j+i <<
" difference of factors = " << j-i << " , " << i-j << "\n";
if(j < i)
system("pause");
break;
return 0;
}
}
}
}
i would be greatful for any help provided.