You are on page 1of 2

Example 2

Problem Description: Calculate the discounted price of an item purchased. Customers receive a discount of
15% on an item if the purchase price of the item is over $100.

The following example shows desk checking involving selection using an IF.

For an IF without an ELSE, if the condition evaluates to True then execution continues to the next line and the
lines between the IF and ENDIF are executed (inclusive), otherwise (the condition is False) execution jumps
from the IF to the ENDIF.

Algorithm  (with line numbers added for the Desk Check)

1 calcPrice()

2     Input price

3     IF price > 100 THEN

4         discount ← price * 15 / 100

5         price ← price - discount

6     ENDIF

7     Display price

8 STOP

Desk Check

Inputs: price = $200


Correct results: price = $170.

Line Number discount price Conditions Input/Output


1        

2   200   Input = Price


200

3     Price  
>100

4 200 x      
15 / 100 = 30
.
5   200 – 30 =    
170 .
6        Output = Price 170

7       .

8        
Inputs: price = $50
Correct results: price = $50.

Line Number discount price Conditions Input/Output


1        

2   50   Price 50

3     50 <100  

4      

5   .    

6        

7       Price = 50

8        

You might also like