C++20 sections · 1024 units
Open in Course

Problem: Validate Range

Checking bounds

Write bool inRange(int value, int min, int max) returning true if value is between min and max inclusive. Use return value >= min && value <= max;. In main, check if a number is between 1 and 100.

Print "Valid" or "Invalid". This pattern appears everywhere: menus, age validation, scores. Test boundaries. Is 1 in range? Is 100? Is 0? Is 101? Boundary bugs are common. Test edges to catch mistakes.