Say that a car has 30000 annual miles.
There will be no discount.
Here is the complete program:
'Car insurance program PRINT "Please enter the base rate" INPUT BASERATE PRINT "Please enter annual mileage" INPUT MILEAGE IF MILEAGE < 20000 THEN IF MILEAGE < 10000 THEN LET DISCOUNT = .1 ELSE LET DISCOUNT = .05 END IF ELSE LET DISCOUNT = 0 END IF PRINT "Your base rate is", BASERATE PRINT "Your discount is", DISCOUNT PRINT "You pay", BASERATE * (1 - DISCOUNT) END
Remember this point:
Complete control structures are treated as a "unit." They (and the statements they control) are completely included or completely excluded from execution.
In the previous (breakfast beverage) program,
the false branch had a nested IF
.
In this program, the true branch has a nested IF
.
Do you suppose that BOTH the true branch and the false branch could have IFs nested inside of them?