๐ŸŒ

Real world โ†’ Pseudocode

Everyday situations are full of algorithms. Spot the INPUT, PROCESS, DECISION and OUTPUT โ€” then write the steps.

๐ŸŒ Real world โ†’ Pseudocode
A customer buys products. If the total exceeds โ‚น5,000, give a 10% discount. Otherwise give no discount.
๐Ÿ“ฅInput

The shopping TOTAL.

โš™๏ธProcess

Work out the discount, then the final amount.

๐Ÿ”€Decision

Is TOTAL more than 5000?

๐Ÿ“คOutput

The FINAL_AMOUNT to pay.

Turn it into pseudocode
1BEGIN2    TAKE TOTAL3    IF TOTAL > 5000 THEN4        SET DISCOUNT = TOTAL * 0.105    ELSE6        SET DISCOUNT = 07    END IF8    SET FINAL_AMOUNT = TOTAL - DISCOUNT9    DISPLAY FINAL_AMOUNT10END
๐ŸŒ Real world โ†’ Pseudocode
An ATM lets you withdraw money only if you have enough balance, and only in multiples of โ‚น100.
๐Ÿ“ฅInput

BALANCE and the AMOUNT requested.

โš™๏ธProcess

Subtract the amount from the balance.

๐Ÿ”€Decision

Is AMOUNT a multiple of 100? Is BALANCE big enough?

๐Ÿ“คOutput

The cash + new balance, or a friendly error.

Turn it into pseudocode
1BEGIN2    TAKE BALANCE, AMOUNT3    IF AMOUNT MOD 100 != 0 THEN4        DISPLAY "Please use multiples of 100"5    ELSE IF AMOUNT > BALANCE THEN6        DISPLAY "Not enough balance"7    ELSE8        SET BALANCE = BALANCE - AMOUNT9        DISPLAY "Take your cash. New balance:", BALANCE10    END IF11END
๐ŸŒ Real world โ†’ Pseudocode
A cinema gives a child ticket (โ‚น150) to anyone under 12, a senior ticket (โ‚น120) from 60 up, and an adult ticket (โ‚น250) otherwise.
๐Ÿ“ฅInput

The visitorโ€™s AGE.

โš™๏ธProcess

Choose the right PRICE.

๐Ÿ”€Decision

AGE = 60?

๐Ÿ“คOutput

The ticket PRICE.

Turn it into pseudocode
1BEGIN2    TAKE AGE3    IF AGE < 12 THEN4        SET PRICE = 1505    ELSE IF AGE >= 60 THEN6        SET PRICE = 1207    ELSE8        SET PRICE = 2509    END IF10    DISPLAY "Ticket price:", PRICE11END