Discuss Scratch

CraZGuy
Scratcher
77 posts

Math "Multipe" Function

Is there a function in scratchblocks that means <multiple of____>? I really need to figure it out or find an alternative way to get the same function.

cvtest
Scratcher
9 posts

Math "Multipe" Function

Hi.

X id multiple of Y

if

Y mod X equals 0

because Y mod X is the modulus function, that returns the remainder of the division of Y by X.
For instance, 137 mod 10 returns 7 because 137 = 13 * 10 + 7
And 7 is not zero, so .. -> no, 137 is not multiple of 10.

Greetz,
Dimitri.


ECLIPSE-STUDIOS
Scratcher
100+ posts

Math "Multipe" Function

Hi,

An alternate version to @cvtest 's method is to use the round block. Simply run the following script:

if
ifNumberA/NumberB=roundNumberA/Bthen

This script check to see whether the result is a whole number. For example: Number A = 20 and number B = 10, 20/10 = 2 And 20/10 rounded to the nearest whole number is 2. And since 2 = 2 (of course), we know that 20 is a multiple of 10. If, however, Number A was 15, 15/10 = 1.5, and 15/10 rounded to the nearest whole number (round 1.5) is 2. Obviously, 1.5 does NOT equal 2, and so 15 is NOT a multiple of 10. This can also be reversed - we can also note from this that 10 is NOT a factor of 15, and 10 IS a factor of 20.

Hope this helps!

Powered by DjangoBB