need help with my loops project

This is a discussion on need help with my loops project within the C++ Programming forums, part of the General Programming Boards category; okay so im having trouble getting the right outputs for this program i am writing for my class.
its supposed ...

need help with my loops project

okay so im having trouble getting the right outputs for this program i am writing for my class.
its supposed to be taking numbers from the user and analyzing them for their divisors(factors)
and also whether they are prime or perfect numbers(i haven't gotten to this point yet).
the problem with the outputs is that it won't put out all the divisors or will put out doubles.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

well the parameters are what we have been taught so far in this class so basically i have to use do while, while, and for loops, the loop does execute but with the way im coding it it just doesn't want to put out either all the divisors or only one iteration of a divisor(as in it will output 1 1 3 4 4)

well the parameters are what we have been taught so far in this class so basically i have to use do while, while, and for loops, the loop does execute but with the way im coding it it just doesn't want to put out either all the divisors or only one iteration of a divisor(as in it will output 1 1 3 4 4)

Yeah, I read your expression as the opposite of what it is.

Code:

for (j = 1; (j <= input) && (input &#37; j == 0); j++)

That loop stops as soon as it reaches a number that is not a divisor. For example, if you enter 100, it will loop with j=1 and find 100 and 1 as divisors; then it will loop with j=2 and find 50 and 2; and then when j=3, input % j != 0, and the loop exits, missing some divisors of 100 including 20 and 25.

That's not what you want. You don't want the loop to stop executing as soon as it finds a number that isn't a divisor. You want the loop to keep going and simply not print anything in this case.

BTW, if you get it working, as written, you'll find every divisor twice. And you won't find a divisor if that divisor is the square root of the number.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell