You can even do better, because
a) number is constant in the inner loop
b) once you have executed the inner loop, total is set to the correct value
So in the end, you can simply do
// 1 is allways a divisor of N total = 1; for (divisor = 2; divisor < number; divisor++) { remainder = number % divisor; if (remainder == 0) { // divisor is a real divisor ? we add it to the total total += divisor; } } // here, total is OK if (total < number) { numberType = "Deficient"; } else if (total == number) { numberType = "Perfect"; } else if (total > number) { numberType = "Abundant"; } cout << number << " is " << numberType << endl;
Now, I don't know what is your current level in C++, but it seems to me that this can be put in a function (with a parameter called "number"). The outer loop itself can be put in a function.
HTH,