cs-009 — The ATM Loop
| Field | Value |
|---|---|
| id | cs-009 |
| difficulty | Beginner |
| topics | flowchart, loops |
| lecture | lecture-03 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | none |
| objective | state inputs, outputs, and assumptions, then solve a small instance by hand |
| solution | held by the instructor; discussed after the attempt |
Problem
Draw a flowchart for an ATM session: PIN with three attempts, then a menu (balance, withdraw, quit) with a balance check on withdrawal.
Your deliverable is the stated assumptions, the rule list, the decision for the worked instance, and one contested case. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: PIN 1234; tries allowed 3; balance 250; withdraw 300 then 100
- Output: fail, fail, fail -> card retained; alternative: 1 fail then withdraw 300 refused, 100 accepted
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- Two nested loops: attempts around the PIN check, menu around the session; the exit test lives on the inner loop.
- Writing the rules IS the solution; code is transcription.
- Every assumption is a place where two good answers can differ.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Propose one extra rule that would change the verdict — is it an improvement?"
Constraints and assumptions
- Difficulty: Beginner (no prior experience assumed).
- Topics: flowchart, loops.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for a first attempt; partial answers with clear reasoning are worth more than silent struggling.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Redraw the flow with one extra decision diamond and argue what changes.