← Back to Week 1 Hub
Sandwich Shop
Calculate the price of a sandwich with age-based discounts
Workbook 1c, p.103 — Project name: sandwich-shop
In Plain English
Build a program for a sandwich shop. The customer picks a size and tells you their age.
Young customers (17 and under) get 10% off. Senior customers (65 and older) get 20% off.
Everyone else pays full price. Show the final cost.
The two sizes are: Regular ($5.45) and Large ($8.95).
The user enters 1 for Regular or 2 for Large.
What a Successful Run Looks Like
Run 1 — Student Discount (10% off)
Enter sandwich size (1 for Regular, 2 for Large): 1
Enter age: 15
Cost of sandwich: $4.91
Run 2 — Senior Discount (20% off)
Enter sandwich size (1 for Regular, 2 for Large): 2
Enter age: 70
Cost of sandwich: $7.16
Run 3 — No Discount
Enter sandwich size (1 for Regular, 2 for Large): 1
Enter age: 30
Cost of sandwich: $5.45
Note: Your prompts and formatting should match the examples above. Pay attention to how the final price is displayed — it uses two decimal places with a dollar sign.
What This Exercise Practices
This exercise reinforces these concepts from Week 1:
Why this matters: This exercise combines user input, conditional logic, and formatted output in a single program. It's your first taste of building something that feels like a real application — taking input, making decisions, and showing a result.
Flow Diagram
Step 1
Ask for size
1 = Regular, 2 = Large
→
Step 2
Look up base price
$5.45 or $8.95
→
Step 3
Ask for age
Scanner input
→
Step 4
Check discount
≤17: 10% / ≥65: 20%
→
Step 5
Calculate price
Apply discount
→
Step 6
Display result
Formatted output
Think about which data type to use for the price. Integers won't work here.