1. always use {} with if statements
2. Your isPrime has some style issues.
checker is a loop variable.
this is an initial condition:
this is an exit condition (and other stuff):
Code:
if(checker <= pow(n , .5) && n % checker == 0)
this is an update statement:
Code:
checker = checker ++;
this is how you make an infinite loop, or one that doesn't have the natural for flow:
but as we just saw, your loop has all the classic for loop elements. So write it as such!
Code:
for(int ix = 2; ix <= pow(n, 0.5); ix++)
{
if((n % ix) == 0)
{
return false;
}
}
return true;
This line deserves special mention:
Code:
if(checker <= pow(n , .5) && n % checker == 0)
This is random nonsense. You are doing two unrelated things in the same line because ???
You have no parens ()! Which means you don't know what it actually does. The reader doesn't know what it actually does. Nobody knows the order of operations between { <=, &&, %, == }. I know what you wish the order was, but wishing doesn't make it so. Just always use parens whenever the whole world isn't absolutely sure about the order of operations. Otherwise you have bugs that your eye can't see.