C++20 sections · 1024 units
Open in Course

Lessons from Nearly Lucky

What we learned

This problem taught you digit extraction with loops. You learned the pattern: modulo 10 gets the last digit, division by 10 removes it. Repeat until the number is 0. This is one of the most common loop patterns in programming.

I showed you how to split complex problems with helper functions. The isLucky function isolates digit-checking logic, making the main solution clearer. When you do similar operations twice, write a helper.

You also learned about edge cases. The count could be 0 if no lucky digits exist, and 0 isn't lucky. Think about boundaries: what if input is 0? What if no matches exist?