Computer Science Canada

need some help with IF

Author:  xxwesley0204 [ Sun Oct 28, 2012 6:42 am ]
Post subject:  need some help with IF

can anyone tell me how to make if be like


if _____(something) = ????????(odd number) then
elsif ________ = ???????(even number) then


how do i do that?

Author:  [Gandalf] [ Sun Oct 28, 2012 7:16 am ]
Post subject:  RE:need some help with IF

Look into Turing's mod operator in the help documentation. The mod (modulo) operator finds the remainder after a division of two numbers. For example, 5 modulo 2 will give 1.

Now, what makes a number even? What makes a number odd?

You can combine these two things to solve your problem.

Author:  xxwesley0204 [ Sun Oct 28, 2012 8:28 am ]
Post subject:  RE:need some help with IF

what do i do if i want to put it like this



loop
locate (11, 27)
put "If you are a male, enter 1"
locate (12, 27)
put "If you are a female, enter 2"
locate (13, 26)
put " " ..
get gender

if gender = "1" then
cls
elsif gender = "2" then
cls
else
cls
locate (11, 26)
put "This gender does not exist."
locate (12, 26)
put "Please enter your gender again."
locate (13, 25)
put " " ..
get gender
cls
exit when gender = "1"
exit when gender = "2"
end if
end loop




i want to add something like:
after this i want to put
if gender = (odd) then
put "mr"
if gender = (even) then
put "ms"

can u show me how to do it?

Author:  Aange10 [ Sun Oct 28, 2012 10:01 am ]
Post subject:  RE:need some help with IF

Well, there is honestly a lot better ways of doing your problem.

But to answer your question:

What Gandalf was hinting at earlier was that you can find out if a number is even or odd using a bit of math. Now what mathematically makes a number even? If it's divisible by two. And what makes a number odd? If it's not divisible by two.

The modulo operation will divide the second number into the first one (5 mod 2 = 5/2) and then give you the remainder (5 mod 2 = 2 remainder 1. Output is 1).

So if you want to find out if a number is even, you mod it by 2 and if there is no remainder it's even. Now how can you tell if it's odd?


FYI: In your program your numbers are held in strings so you may need to use ints or use the strint() command to turn them into ints.

Author:  chipanpriest [ Wed Oct 31, 2012 7:13 pm ]
Post subject:  RE:need some help with IF

Turing:

If gender = 1 then
put "Mr."
elseif gender = 2 then
put "Mrs."


Why can't you just do that?


: