← Back to Week 1 Hub
Rental Car Calculator
Calculate the total cost of a car rental with optional extras and age surcharge
Workbook 1c, p.124-125 — Project name: rental-car-calculator
In Plain English
Build a rental car cost calculator. The customer tells you when they're picking up, how many days
they need, and which optional extras they want (toll tag, GPS, roadside assistance — each costs
extra per day). They also give their age — drivers under 25 pay a 30% surcharge on the base car
rental. At the end, show a summary of everything and the total cost.
What a Successful Run Looks Like
Run 1 — Under 25 with Options
Enter pickup date (mm/dd/yyyy): 03/15/2026
Enter number of rental days: 3
Do you want an electronic toll tag (y/n)? y
Do you want a GPS (y/n)? n
Do you want roadside assistance (y/n)? y
Enter your age: 22
Rental Summary
--------------
Pickup date: 03/15/2026
Rental days: 3
Car rental rate: $29.99 per day
Options cost: $23.70
Underage driver surcharge: $26.99
Total cost: $140.66
Car: 3 x $29.99 = $89.97. Options: 3 x ($3.95 + $3.95) = $23.70. Surcharge: $89.97 x 0.30 = $26.99. Total: $140.66
Run 2 — Over 25, No Options
Enter pickup date (mm/dd/yyyy): 04/01/2026
Enter number of rental days: 5
Do you want an electronic toll tag (y/n)? n
Do you want a GPS (y/n)? n
Do you want roadside assistance (y/n)? n
Enter your age: 30
Rental Summary
--------------
Pickup date: 04/01/2026
Rental days: 5
Car rental rate: $29.99 per day
Total cost: $149.95
Car: 5 x $29.99 = $149.95. No options, no surcharge. Total: $149.95
Key detail: The 30% surcharge applies only to the base car rental cost ($29.99/day x days) — it does not apply to the optional extras. Also notice that lines like "Options cost" and "Underage driver surcharge" only appear when they are relevant.
What This Exercise Practices
This exercise reinforces these concepts from Week 1:
Why this matters: This is one of the most complete exercises in Week 1 — it combines multiple inputs, string comparisons for yes/no answers, conditional logic for the age surcharge, arithmetic with constants, and formatted output. Getting this one right means you can handle real-world calculator programs.
Flow Diagram
Step 1
Ask for pickup date
String input
→
Step 2
Ask for rental days
int input
→
Step 3
Ask about toll tag
y/n — $3.95/day
Step 4
Ask about GPS
y/n — $2.95/day
→
Step 5
Ask about roadside assistance
y/n — $3.95/day
→
Step 6
Ask for age
int input
Step 7
Calculate car rental cost
$29.99 x days
→
Step 8
Calculate options cost
Sum selected options x days
→
Check
Under 25?
Yes
Add 30% surcharge
On car rental cost only
No
No surcharge
Skip this step
Step 9
Calculate total
Car + options + surcharge
→
Output
Display summary
Formatted with $
Think about which values should be final constants. How will you compare the user's y/n answers to decide which options to include?