The TRUE/FALSE question picks or rejects a single option, rather than picking one of two options.
The "cookie problem" is about whether to do something extra. The choice is about whether to add a visit to the cookie shop to your shopping trip. Here is a QBasic program that imitates the cookie problem. The user types "1" if hungry, and "0" if not:
PRINT "Enter 1 if you are hungry; 0 if you are not" INPUT HUNGER ' IF HUNGER > 0 THEN PRINT "Buy Cookies" ' true branch END IF ' PRINT "Keep Shopping" ' this statement is always done END
The words IF
, THEN
, and END IF
are brackets that divide
the program into branches.
This is just like the decisions of the previous chapter,
but now the only branch is the true branch.
IF
statement always asks a question
(usually about the number in a variable.)
END IF
.
The user runs the program and enters "1". What will the program print?