Skip to main content

Practice · 1 of 2

std::optional divide

CHALLENGE
Difficulty: intermediate+25 XP

Implement std::optional<int> safe_divide(int a, int b): return the quotient when b != 0, and std::nullopt when b == 0. No exceptions, no sentinel ints.

Back to lesson: Practice: optional and enum practice