Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Problem - Is there a different command for or?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Namis




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Sep 22, 2003 3:43 pm   Post subject: (No 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=...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




PostPosted: Mon Sep 22, 2003 4:10 pm   Post subject: (No 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++?)
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Tony




PostPosted: Mon Sep 22, 2003 4:55 pm   Post subject: (No 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
krishon




PostPosted: Mon Sep 22, 2003 4:55 pm   Post subject: (No subject)

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




PostPosted: Mon Sep 22, 2003 6:51 pm   Post subject: (No 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
Blade




PostPosted: Mon Sep 22, 2003 7:59 pm   Post subject: (No 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
Namis




PostPosted: 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?

Blade




PostPosted: Wed Sep 24, 2003 9:39 pm   Post subject: (No 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 ":="
Tony




PostPosted: Wed Sep 24, 2003 10:03 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Namis




PostPosted: Wed Sep 24, 2003 10:03 pm   Post subject: (No subject)

:= doesnt work, anyway

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

silly me

thanks tony
Namis




PostPosted: Wed Sep 24, 2003 10:08 pm   Post subject: (No subject)

got it working, thanks :O
krishon




PostPosted: Thu Sep 25, 2003 6:01 pm   Post subject: (No subject)

lol, bout the to Uppercase function.........java does that automatically for u Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: