What is the fare paid by someone who is 23 years old when the base fare is $100?
$70. The second test is true, so its branch is executed:
ELSEIF AGE < 24 THEN LET RATE = 0.70
Remember that with the IF-ELSEIF
structure only one branch is picked.
The computer starts at the top and goes down the list of conditions
until it finds the first one that is true.
That determines the one branch that is executed.
In this example, AGE < 24 is the first true condition,
so its branch is executed:
PRINT "Enter full fare" INPUT FARE <-- 100 PRINT "Enter age" INPUT AGE <-- 23 ' 'Calculate discount based on age IF AGE < 12 THEN <-- false LET RATE = 0.0 ELSEIF AGE < 24 THEN <-- true LET RATE = 0.70 <-- this branch picked ELSEIF AGE < 65 THEN LET RATE = 1.0 ELSE LET RATE = 0.75 END IF 'Calculate fare PRINT "Your fare is:", FARE * RATE <-- this statement is done next END
It is also true that AGE < 65 but this is not the first true condition, so its branch is not picked.
What is the fare paid by someone who is 77 years old when the base fare is $100?