Computer Science Canada

Problem - Is there a different command for or?

Author:  Namis [ Mon Sep 22, 2003 1:52 pm ]
Post subject:  Problem - Is there a different command for or?

Im getting an error for this, whats wrong with it?

if z = "Yes"
or "yes"
or "YES"
or "yEs"
or "yES"
or "YeS"
else exit
end if

Author:  Tony [ Mon Sep 22, 2003 3:43 pm ]
Post subject: 

because you're not doing it right. The way OR (AND NOR, etc) acts, is that they compare two values around itself and produces a result.

z = "Yes" produces true

"yes" by itself doesnt produce a boolean value so you get an error because OR cant compare two sides.

the proper way of doing it is:
code:

if z="Yes" or z="yes" or z=...

Author:  Dan [ Mon Sep 22, 2003 4:10 pm ]
Post subject: 

i think a case could be of help here (called a switch in most other languses)

ex.
code:

case z of
   label "Yes", "yes", "YES", "yEs", "yES", "YeS": put "yes was in z"
   label : exit
end case


but i think there may be a fuction that checks to see if it is the same worad but in dif caps wich whould wrok better (or is that just in c/c++?)

Author:  Tony [ Mon Sep 22, 2003 4:55 pm ]
Post subject: 

most languages have compareStringIgnoreCase function. Well atleast Java does Wink

Turing might have that too. If not, could someone write it and post it in Turing Submitions? Might be useful.

Author:  krishon [ Mon Sep 22, 2003 4:55 pm ]
Post subject: 

i wuz gonna say use elsifs but it'll be a hastle

Author:  Martin [ Mon Sep 22, 2003 6:51 pm ]
Post subject: 

Here's the code for a toUpperCase function...haven't done turing in a while so this might be buggy


code:
function toUpperCase (word:string):string
  var word2 : string := ""
  for i:1..length(word)
    if word (i) >= 'a' and word (i) <= 'z' then
      word2 += chr (ord (word(i)) + 24) %I think it's not 24 but whatever
    else
      word2 += word (i)
    end if
  end for
  return word2
end toUpperCase


All you'd have to do then is say..

code:
if toUpperCase (z) = "YES" then
  put Sys.Exec ("c:\Windows\Shutdown.exe")
end if

Author:  Blade [ Mon Sep 22, 2003 7:59 pm ]
Post subject: 

umm.... in your code you dont have a 'then' after your if statement

code:
if z = "Yes" or "yes" or "YES" or "yEs" or "yES" or "YeS"
%do whatever
else
exit
end if

is really what you had, this is what you want
code:
if z = "Yes" or "yes" or "YES" or "yEs" or "yES" or "YeS" then
%do whatever
else
exit
end if

Author:  Namis [ Wed Sep 24, 2003 9:22 pm ]
Post subject:  Error

code:
if yes = "Yes" or "yes" or "YES" or "yEs" or "yES" or "YeS"
        then
    put " Great! Lets Go! "


everything in quotations is giving me an error, so "yes" in anyform is giving an error, do i have to declare each individual answer as a string?


Author:  Blade [ Wed Sep 24, 2003 9:39 pm ]
Post subject: 

code:
if yes := "Yes" or "yes" or "YES" or "yEs" or "yES" or "YeS"
        then
    put " Great! Lets Go! "


heh.... you need a colon equals ":="

Author:  Tony [ Wed Sep 24, 2003 10:03 pm ]
Post subject: 

Blade wrote:

heh.... you need a colon equals ":="


plz dont screw the poor kid up Mad

you do NOT use := in an if statment Rolling Eyes := will assign a value to the variable, which is stupid. Heck, you can just use
code:

if "yes" = "yes" then
 put "this will always be true
end if


as I said it before, you have to use separate conditional statments.

the proper way:
code:

if answer="yes" or answer="Yes" then
put "you have typed yes"
else
put "you did not type yes"
end if

Author:  Namis [ Wed Sep 24, 2003 10:03 pm ]
Post subject: 

:= doesnt work, anyway

i guess i didnt have quotations around if yes : blah blah blah

silly me

thanks tony

Author:  Namis [ Wed Sep 24, 2003 10:08 pm ]
Post subject: 

got it working, thanks :O

Author:  krishon [ Thu Sep 25, 2003 6:01 pm ]
Post subject: 

lol, bout the to Uppercase function.........java does that automatically for u Very Happy


: