Author |
Message |
jayshaw94
|
Posted: Thu Apr 21, 2011 12:03 pm Post subject: loop |
|
|
When running this code below. If the person types in an answer that is within the limit (0,0.5,1,2)
I still get the error message. What am I doing wrong?
Thanks in advance!
var nojp:int
var op1:real
procedure OpeningDeductions
put "Enter the number of Jumbo post(s) required"
get nojp
put "Enter either 0, 0.5, 1, or 2"
loop
get op1
if op1 not = 0 or op1 not = 0.5 or op1 not = 1 or op1 not = 2 then
put "Error please enter the following 0, 0.5, 1, or 2"
put op1
end if
exit when op1 = 0 or op1 = 0.5 or op1 = 1 or op1 =2
end loop
end OpeningDeductions |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
|
|
|
 |
jayshaw94
|
Posted: Thu Apr 21, 2011 12:30 pm Post subject: Re: loop |
|
|
sorry Tony not sure what you mean. The program runs but I still get the error message if for instance i type in 5 I'll get the error message as I should. But if i type in one of the options available I get the error message but it continues onto the next line of code |
|
|
|
|
 |
Insectoid

|
Posted: Thu Apr 21, 2011 12:46 pm Post subject: RE:loop |
|
|
Say someone enters 1. Now we check.
Does it equal 0? No.
Does it equal 0.5? No.
Does it equal 1? Yes!
The test fails, and we therefore get your error message.
'or' is obviously not working here. Try something else. |
|
|
|
|
 |
Tony

|
Posted: Thu Apr 21, 2011 12:47 pm Post subject: RE:loop |
|
|
oh, that.
code: |
op1 not = 0 or op1 not = 0.5 or op1 not = 1 or op1 not = 2
|
is guaranteed to always be true, for any value entered.
edit: damn you Insectoid! |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Insectoid

|
Posted: Thu Apr 21, 2011 12:48 pm Post subject: RE:loop |
|
|
I win again! |
|
|
|
|
 |
jayshaw94
|
Posted: Thu Apr 21, 2011 1:48 pm Post subject: Re: loop |
|
|
thanks guys what other syntax would i be able to use? |
|
|
|
|
 |
Tony

|
Posted: Thu Apr 21, 2011 2:00 pm Post subject: RE:loop |
|
|
OR could work, if you ask the right question. Keep in mind that this is a mathematical OR. In speech "or" often means "xor" instead, thus the confusion.
Some references
or
xor
and
not |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Sponsor Sponsor

|
|
 |
jayshaw94
|
Posted: Thu Apr 21, 2011 3:27 pm Post subject: Re: loop |
|
|
Thank you Tony I'll look into it some more
thanks again |
|
|
|
|
 |
|