Computer Science Canada simple if statement question XD |
Author: | doughbluegurll [ Mon Dec 22, 2008 2:44 pm ] |
Post subject: | simple if statement question XD |
um i want it to only output when the variable is an integer is that possible? like say i have variables x y and quotient where quotient = x/y but i only want it to put quotient when it is an integer(when its divisible) thanks!~ (hope i didn't break ne rules >_>) |
Author: | Insectoid [ Mon Dec 22, 2008 3:18 pm ] |
Post subject: | RE:simple if statement question XD |
use mod. If x mod y = 0 then x/y = integer. |
Author: | TheGuardian001 [ Mon Dec 22, 2008 3:22 pm ] | ||
Post subject: | Re: simple if statement question XD | ||
you would have to know a bit about type casting/type conversion(converting on type, for example an integer, to another, like a string) you should look into the realstr, intstr, and strintok commands. for example:
if you still don't understand type conversion, you should look it up in the Turing help file |
Author: | Insectoid [ Mon Dec 22, 2008 3:26 pm ] | ||
Post subject: | RE:simple if statement question XD | ||
TheGuardian, that is not a good way to go about doing this. Mod is best. Mod returns the remainder of division. Remember remainders from back in grade 2? So, if there is a remainder, the result of x/y will not be an integer. If x mod y = 0, there is no remainder, x and y divide equally, and you get an integer.
|
Author: | Clayton [ Mon Dec 22, 2008 3:46 pm ] | ||
Post subject: | RE:simple if statement question XD | ||
Or as an alternative:
|
Author: | doughbluegurll [ Mon Dec 22, 2008 3:53 pm ] |
Post subject: | RE:simple if statement question XD |
okies got it!~ thanks so much!~ |