Yes, it is at the right time, but I would amend the setting of result to be:
```
if (result == 0) result = 1;
```