Back to challenges
Easy 0 solved 0% acceptance

Ticket Price by Age

Choose a cinema ticket price from the visitor's age.

What you'll learn

  • Choose a value from age ranges
  • Write non-overlapping conditions
  • Test boundary ages

Problem

A cinema charges by age: children under 3 are free, ages 3–12 pay 5, ages 13–64 pay 12, and 65 or older pay 7.

Implement ticket_price(age).

Input

age: The visitor's age in years.

Output

Return the ticket price.

Constraints

0 ≤ age ≤ 120

Examples

Example 1
Input:
age = 10

Expected output:
expected = 5
Input:
long long age = 10;

Expected output:
long long expected = 5;
Input:
long age = 10;

Expected output:
long expected = 5;

Explanation

10 is between 3 and 12, so the price is 5.

Example 2
Input:
age = 70

Expected output:
expected = 7
Input:
long long age = 70;

Expected output:
long long expected = 7;
Input:
long age = 70;

Expected output:
long expected = 7;

Explanation

70 is 65 or older, so the senior price of 7 applies.

How to approach it

Try on your own first, then open one hint at a time.

Hint 1

The price depends on which age band the visitor falls into.

Hint 2

Check the youngest and oldest special cases before the middle ranges.

Hint 3

Pay attention to the exact endpoints so ages 3, 13, and 65 get the correct prices.

Expected complexity

O(1) time, O(1) extra space

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.