Gentleman,
I have the following question:
9. Present an example of a logic bug using pseudocode and explain your
answer. (10 points) I just want the group to verify if my answer is
correct.
Here is my answer:
Temperature = 70
if (Temperature >69) and (Temperature < 100 )
THEN
openWindows;
Will work because if temperature is higher than 69 degrees and
temperature is lower than 100 degrees windows will open.
The code generated: A numbered list from 70 - 99
--------------------------------------------------------------------------- --------------------------------------------------------------------------- -----------------------
I then ran erroneous code below changing the "and" operator to "or"
which is an infinite loop.
Temperature = 70
if (Temperature >69) or (Temperature < 100 )
THEN
openWindows;
Won't work because windows will stay closed due to temperature will
always be under 100 degrees the fault lies with the "or" "||" operator
which was used instead of the "and" (&&) operator.
The code generated: an infinite loop.
Thank You,
Ray