Author |
Message |
Angel
|
Posted: Sun Jan 04, 2004 6:52 pm Post subject: Operands of comparison |
|
|
I'm having a problem with a program I'm writing, and there's something wrong with the operands of comparison:
code: | put ""
put "Question 10:"
put ""
put "Mila Kunis, the star of the hit TV show, That 70's Show and the star of American Psycho 2 was born in:"
put ""
put "1) Portugal"
put "2) Ukraine"
put "3) Austria"
put ""
put "Please enter the number of your selection: " ..
get questions1 (3)
if questions1 (3) > 3 or questions1 (3) = 0 then
put "This is not a choice."
put "Please select another choice: " ..
loop % Will rerun the program when the user chooses "label"
get questions1 (3)
exit when questions1 (3) => 1 or questions1 (3) =< 3
put "Please select another choice: " ..
end loop
end if |
This is an example code that I am using. When I try to run the program, it highlights the following:
code: | exit when questions1 (3) => 1 or questions1 (3) =< 3 |
It says that there's a syntax error at '<'. Help?! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
Angel
|
Posted: Sun Jan 04, 2004 7:24 pm Post subject: (No subject) |
|
|
Yeah I've tried that too but then it highlights the number and says that Operands of boolean operators must be Boolean. And I have no clue what it means. Ok do you think that it might have anything to do with the fact that I declared questions1 as an array of int? |
|
|
|
|
|
Tony
|
Posted: Sun Jan 04, 2004 7:30 pm Post subject: (No subject) |
|
|
exit when might be buggy... try to spit it into two
exit when >= 1
exit when <= 3 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Angel
|
Posted: Sun Jan 04, 2004 7:42 pm Post subject: (No subject) |
|
|
I get the same crap... I really don't wanna do it the long way and type out the stuff using or!!! |
|
|
|
|
|
DanShadow
|
Posted: Sun Jan 04, 2004 7:54 pm Post subject: (No subject) |
|
|
Im assuming your "questions1" variable is an array right? What kind of variable is it? (int/string/char) Oh, and wh en trying to get an answer from a user..try using a loop, it works for me.
code: |
var answer:int:=0
loop
locate(1,1)
put "Which language is better: "
put "[1] C++"
put "[2] Java"
put "[3] Turing, which really is C++"
put ""
put "Answer: "..
get answer
exit when answer>0 and answer<4
end loop
|
hmm...I think I found your error!
Your exit is saying:
I will exit when questions(3) is greater or equal to 1, or when questions1(3) is less or equal to 3. Hmm....this doesnt make sense.....how can I exit using an "or" statement, which both sides of the or statement lead to the same thing????
In other words, you cant have it so its checking if the answer is greater or equal to 1, or less or equal to three, it must be and AND s tatement.
code: |
exit when questions1(3)>=1 and questions1(3)<=3
|
Hope this helps! |
|
|
|
|
|
Angel
|
Posted: Sun Jan 04, 2004 8:02 pm Post subject: (No subject) |
|
|
You know, when I looked at it again I thought the same thing... but changed the or statement to an and didn't help. And it is an int array. I do have the "get answer" in a loop:
code: | loop
get questions1 (2)
exit when questions1 (2) => 1 and questions1 (2) =< 3
put "Please select another choice: " ..
end loop |
So I have no idea what's wrong! And because of that one little stupid error, my whole program doesn't work! Any other ideas except typing the whole thing out? e.g. exit when questions1(2) =>1 or questions1(2) = 2... etc. |
|
|
|
|
|
Ashkan
|
Posted: Sun Jan 04, 2004 11:52 pm Post subject: (No subject) |
|
|
code: |
put ""
put "Question 10:"
put ""
put "Mila Kunis, the star of the hit TV show, That 70's Show and the star of American Psycho 2 was born in:"
put ""
put "1) Portugal"
put "2) Ukraine"
put "3) Austria"
put ""
put "Please enter the number of your selection: " ..
var questions1 : int
loop
get questions1
exit when questions1 > 0 and questions1 < 4
put "This is not a choice."
put "Please select another choice: " ..
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Ashkan
|
Posted: Sun Jan 04, 2004 11:58 pm Post subject: (No subject) |
|
|
simply you can use this one two basiclly same but since you want to know your mistake its like puting <= not >= and i made your code simpler
code: |
put ""
put "Question 10:"
put ""
put "Mila Kunis, the star of the hit TV show, That 70's Show and the star of American Psycho 2 was born in:"
put ""
put "1) Portugal"
put "2) Ukraine"
put "3) Austria"
put ""
put "Please enter the number of your selection: " ..
var questions1 : int
loop
get questions1
exit when questions1 >= 1 and questions1 <= 3
put "This is not a choice."
put "Please select another choice: " ..
end loop
|
|
|
|
|
|
|
Angel
|
Posted: Mon Jan 05, 2004 10:47 pm Post subject: (No subject) |
|
|
Thanks guys! |
|
|
|
|
|
|