You did everything right except you forgot to return when the user enters a negative number.
You can handle exceptional cases by throwing an exception. But for your simple example, you can just ...