margaret Posted March 4, 2011 Report Share Posted March 4, 2011 I want to test whether a number is a multiple of 5. Is there a way to test whether the result of a division is an even number? I've tried testing whether the last digit is a 0 or a 5 but so far it's not working. Thanks. Quote Link to comment Share on other sites More sharing options...
paul Posted March 5, 2011 Report Share Posted March 5, 2011 1) Divide your number by 5, save this result (res1) 2) Multiply res1 by 5, save this result (res2) 3) If your number equals res2, your number is divisible by 5 Same with odd/even numbers, using 2 as the divisor. Quote Link to comment Share on other sites More sharing options...
kevin Posted March 5, 2011 Report Share Posted March 5, 2011 1) Divide your number by 5, save this result (res1) 2) Multiply res1 by 5, save this result (res2) 3) If your number equals res2, your number is divisible by 5 Same with odd/even numbers, using 2 as the divisor. This works if you are using Integer variables. Something like this might work if you want to use Decimal variables: Variable Modify Decimal: %D2% = %D1% / 5 Variable Modify Decimal: Copy fraction part of %D2% to %D3% Variable Modify Decimal: %D4% = %D3% * 5 Round Decimal Variable %D4% to 0 decimal places If Variable %D4% = 0 // Divisible by 5 Else // Not divisible by 5 End If Quote Link to comment Share on other sites More sharing options...
margaret Posted March 5, 2011 Author Report Share Posted March 5, 2011 1) Divide your number by 5, save this result (res1) 2) Multiply res1 by 5, save this result (res2) 3) If your number equals res2, your number is divisible by 5 Same with odd/even numbers, using 2 as the divisor. I'm afraid this doesn't make sense to me. Isn't dividing by 5 and then multiplying by 5 the same thing as multiplying by 1?? 125 / 5 = 5. 5 x 5 = 125. Quote Link to comment Share on other sites More sharing options...
paul Posted March 5, 2011 Report Share Posted March 5, 2011 I'm afraid this doesn't make sense to me. Isn't dividing by 5 and then multiplying by 5 the same thing as multiplying by 1?? 125 / 5 = 5. 5 x 5 = 125. Try these: 124/5 = 24 24*5 = 120 125 <> 120, therefore 124 is not a multiple of 5 125/5 = 25 (not 5 as you wrote above) 25*5 = 125 125 = 125, therefore 125 is a multiple of 5 QED Quote Link to comment Share on other sites More sharing options...
margaret Posted March 6, 2011 Author Report Share Posted March 6, 2011 Meanwhile, I just went about it a different way. If last digit of variable equals five Or If last digit of variable equals zero Else ----- warn the user that his input variable is not a multiple of five End If Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.