' Tuning Fork Program ' PRINT "Enter the frequency (37-32000):" INPUT FREQ IF FREQ >= 37 AND FREQ <= 32000 THEN SOUND FREQ, 18 ELSE PRINT "Frequency is out of range" END IF ' END
Here is what happens when the user enters a FREQ
that is too low, 20 for example:
FREQ >= 37 AND FREQ <= 32000
---------- ----------
false AND true
------------------
false
FREQ must meet two requirements at the same time:
FREQ must be equal or greater than 37 : FREQ >= 37FREQ must be less than or equal to 32000 : FREQ <= 32000On a "number line" this looks like this:
............+--------------------------------+....................>
0 37 32000
FREQ must be in this range
To check that FREQ is in the required range you have to use two
relational expressions: one to check that FREQ is not too low,
another to check that FREQ is not too high.
Then the two are combined with AND, since both tests must be passed.
Fill in the blanks in the following IF statement so that
the true branch will execute when X
is in the range of 100 to 200, inclusive.
In math this is written: 100 <= X <= 200.
IF ________________________ AND _____________________ THEN