Author |
Message |
Namis
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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=...
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Dan
![](http://wiki.compsci.ca/images/archive/3/3c/20100325043407!Danspic.gif)
|
Posted: 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! |
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Sep 22, 2003 4:55 pm Post subject: (No subject) |
|
|
most languages have compareStringIgnoreCase function. Well atleast Java does
Turing might have that too. If not, could someone write it and post it in Turing Submitions? Might be useful. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
krishon
|
Posted: Mon Sep 22, 2003 4:55 pm Post subject: (No subject) |
|
|
i wuz gonna say use elsifs but it'll be a hastle |
|
|
|
|
![](images/spacer.gif) |
Martin
![](http://www.compsci.ca/wiki/images/4/46/CanadianStickUp.jpg)
|
Posted: 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 |
|
|
|
|
|
![](images/spacer.gif) |
Blade
|
Posted: 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 |
|
|
|
|
|
![](images/spacer.gif) |
Namis
|
Posted: 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?
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Blade
|
Posted: 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 ":=" |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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
you do NOT use := in an if statment := 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
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Namis
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Namis
|
Posted: Wed Sep 24, 2003 10:08 pm Post subject: (No subject) |
|
|
got it working, thanks :O |
|
|
|
|
![](images/spacer.gif) |
krishon
|
Posted: 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 Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
|