An ATM (Automated Teller Machine) withdrawal process works as follows: The user enters their PIN (Personal Identification Number) If the PIN is wrong, they ...

Assessment: Computer Science (9-1) 0984 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science (9-1) - 0984

Question 1 Report

An ATM (Automated Teller Machine) withdrawal process works as follows:

  • The user enters their PIN (Personal Identification Number)
  • If the PIN is wrong, they get up to 3 attempts
  • If the PIN is correct, they enter a withdrawal amount
  • The amount must be a multiple of 10 and not exceed the balance

(a) Write pseudocode for this ATM withdrawal algorithm. Assume the correct PIN is stored in a variable StoredPIN and the account balance is in a variable Balance. [8]

(b) Complete the trace table for the following scenario: StoredPIN = "1234", Balance = 500. User enters PIN "0000", then "1234", then amount 80. [4]

StepPIN enteredAttemptsPIN correct?AmountValid amount?BalanceOUTPUT
1
2
3

Answer Details

(a) The pseudocode implements an ATM withdrawal with PIN verification (up to 3 attempts) and amount validation (multiple of 10, within balance). [8]

DECLARE StoredPIN : STRING
DECLARE EnteredPIN : STRING
DECLARE Balance : REAL
DECLARE Amount : INTEGER
DECLARE Attempts : INTEGER
DECLARE Authenticated : BOOLEAN

Attempts ← 0
Authenticated ← FALSE

REPEAT
    OUTPUT "Enter PIN: "
    INPUT EnteredPIN
    Attempts ← Attempts + 1
    IF EnteredPIN = StoredPIN THEN
        Authenticated ← TRUE
    ELSE
        OUTPUT "Incorrect PIN. ", 3 - Attempts, " attempts remaining."
    ENDIF
UNTIL Authenticated = TRUE OR Attempts >= 3

IF Authenticated = FALSE THEN
    OUTPUT "Card locked. Contact your bank."
ELSE
    REPEAT
        OUTPUT "Enter withdrawal amount (multiple of 10): "
        INPUT Amount
        IF Amount MOD 10 <> 0 THEN
            OUTPUT "Amount must be a multiple of 10"
        ELSE
            IF Amount > Balance THEN
                OUTPUT "Insufficient funds. Balance: ", Balance
            ELSE
                Balance ← Balance - Amount
                OUTPUT "Dispensing ", Amount
                OUTPUT "Remaining balance: ", Balance
            ENDIF
        ENDIF
    UNTIL Amount MOD 10 = 0 AND Amount <= Balance
ENDIF

The PIN loop uses a REPEAT...UNTIL that exits when the PIN matches or 3 attempts are exhausted [1]. The attempt counter increments before the check so the limit is enforced correctly [1]. After authentication, a second loop handles the amount, rejecting non-multiples of 10 and amounts exceeding the balance [1].

(b) Trace for StoredPIN = "1234", Balance = 500, inputs: "0000", "1234", amount 80: [4]

StepPIN enteredAttemptsPIN correct?AmountValid amount?BalanceOUTPUT
100001No--500Incorrect PIN. 2 attempts remaining.
212342Yes--500(proceeds to amount entry)
3-2Yes80Yes (80 MOD 10 = 0, 80 ≤ 500)420Dispensing 80, Remaining balance: 420

The first attempt fails, consuming one of three tries [1]. The second attempt succeeds, so the loop exits with Authenticated = TRUE [1]. The amount 80 passes both checks (divisible by 10, within balance), so 80 is subtracted from 500 [1].

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning