1 2 3 4
|
while(condition)
{
//code
}
|
The code portion will only execute
while condition is true. Say the user enters 14, when the code reaches the loop (12 % 1 == 0) is true, so the code enters the loop, then at the end, tests it again, with nCount being 2 now, so (12 % 2 == 0) is also true, then it tries it again, with nCount being 3, (14 % 3 == 0 ) is false, so now you do not reenter the loop, you are done with it, and because that is the last line of the code, the program ends. What you probably want to do is repeat the loop while nCount is smaller then nPrime, and use an if statement to see if
nPrime % nCount == 0
is true from within the loop, and if it is, then display that nCount.