I am new to C++ programming, and have this homework where I need to find all the perfect numbers to 1000.
I have worked on this problem for a while now, and really trying to get it figured out, but I'm doing something wrong. I was wondering if someone could turn my head as to what it is.
This is just a snippet of the code in question. Thanks in advance for any help you can give.Code:int testNum = 2; //the number to be tested to see if its perfect - i started it ith 2 since the perfect number must be the sum of all divisors excluding itself. int testDiv; //this sets test divisors to see if it goes into the number int accum = 0; // sums the divisors to see if they equal the test number int counter = 2; // count started at 2 siunce I know that there are none at 1 while( counter < 1000) { for (int testDiv = 1; testDiv < testNum; testDiv++) { if(testNum % testDiv == 0) { accum += testDiv; } if (accum == testNum) { cout << testNum << " is a perfect number less than 1000." <<endl; } } counter++; testNum++;