I'm such a dunce, I wrote a post expanding on all of that and how to check if a number is evenly divisible
and completely forgot about the modulus operator. That little % sign in AngleWyrm's example is called the modulus operator and is used to check if a number is evenly divisible by another number. It is a critical step in finding primes. Go look it up to better understand the sample.
I think it might also be worth explaining casting. In Wyrm's example:
int divisor = (int) sqrt(test_value);
sqrt() takes and returns a double, which is like a float but more precise.
It lets you store non-whole numbers. sqrt(42) would yield 6.48. But what he wants is 6, not 6.48. So it needs to be converted somehow...
Recall than the int datatype
cannot store the number 6.48. If you wrote code like this:
int divisor = sqrt(test_value);
It would take the value 6.48 and shove it into an int slot. (The computer will convert it on the fly.) The value 6 will be stored, which is what's wanted.
But the compiler will give you a warning about an implicit cast. It gives you this warning because
in that conversion, data is thrown away, and if you wrote such code on accident, it can break your program. Under some circumstances it could also misunderstand what you want. So...
You must communicate to the compiler that you specifically
want to cast it from float to integer.
By putting the target data type in parenthesis before a value, you perform an
explicit cast. Here's the code again with the cast highlighted:
int divisor = (int) sqrt(test_value);
Putting that before the value tells the compiler "I want to convert this from its current data type to an int; I understand what this does and have made a conscious decision".
And that will get rid of the warning.