simple if statement question XD
Author |
Message |
doughbluegurll
|
Posted: 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 >_>) |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: 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. |
|
|
|
|
 |
TheGuardian001
|
Posted: 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:
Turing: |
var inputString : string %create string variable
get inputString %get input
if strintok(inputString ) then %if it can be converted to an integer
put "you entered an integer!"
elsif strrealok(inputString ) then %check if string variablecan be converted to real variable
put "you entered a real number!"
else %not int or real
put "you didn't enter an integer or a real number!"
end if
|
if you still don't understand type conversion, you should look it up in the Turing help file |
|
|
|
|
 |
Insectoid

|
Posted: 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.
code: |
if x mod y = 0 then
put x / y
end if
|
|
|
|
|
|
 |
Clayton

|
Posted: Mon Dec 22, 2008 3:46 pm Post subject: RE:simple if statement question XD |
|
|
Or as an alternative:
Turing: | if round (x / y ) = x / y then
put x / y
end if |
|
|
|
|
|
 |
doughbluegurll
|
Posted: Mon Dec 22, 2008 3:53 pm Post subject: RE:simple if statement question XD |
|
|
okies got it!~ thanks so much!~ |
|
|
|
|
 |
|
|