I am currently creating an AppleScript program that lets you see if the number you enter is divisible by another number. The code I use to see if my number is divisible by two (I think) works just fine:
set twoCheck to (round (myNumber / 2))
set twoCheck to (twoCheck * 2)
if twoCheck = myNumber then
set twoCheck to true
else
set twoCheck to false
end if
To determine if a number is divisible by three, you add up all of the digits in the number, and if the sum is divisible by three, so is the original number. I use this code to find the sum of the digits from the my number:
set numString to (myNumber as string)
set numCount to (number of characters of numString)
set threeCheck to 0
set numSelect to 1
repeat numCount times
set threeCheck to (threeCheck + (character numSelect of numString))
set numSelect to (numSelect + 1)
end repeat
This code works just fine. I figured that if I used the same code to see if my number is divisible by two and just replace the two with threes, it would execute just fine and tell me if the sum of the digits is divisible by three. However, this not the case. It always returns either "true" or "false", and it's almost never accurate.
Maybe this is super obvious, and I apologize, but I'm stumped here. Keep in mind that I want to find if the number I enter is divisible by any number, not just the number three (although in this case I do want to find if it's divisible by three, but in other words, this code needs to be expandable to other numbers).
I'm fairly new to AppleScript and it'd be great if I could get some help on this. Thanks.
set theMod to x mod y
(with x ≥ y and x,y=integers)! If theMod=0 x is divisible by y