Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Cool recursion
For some reason Codewars submitted an unrefactored version of this solution. The final version of this is very different and removes a lot of the unnecessary elements in this version.
Because we are dealing with integers, C# division or modulus by zero already throws a DivideByZeroException. There's no need to explicitly build and throw one. If we were using floats or doubles, we would get one of the infinities (or in the case of 0.0 / 0.0 or 0.0 % 0.0, NaN) as a result and would need to do further work to handle that.
This is the correct "best practices" solution.
A fantastic kata, one of the best!!
That is my point, except that "N/A or an infinite number of years" in this case means an infinite loop, causing the application to freeze. This would not be best practices, as over 100 votes have claimed.
If invalid input is given to this method, it doesn't indicate it by either a returned value or an exception; instead, it just never returns at all.
That is what my question was trying to illuminate: if tax is not less than 1 or if interest is not greater than 0, what happens is a frozen application.
If tax is = 1 or more that means they're being taxed at 100% or more.
They will never meet the DesiredPrincipal and the answer is now N/A or an infinite number of years, because no matter how many years this man waits his initial value will never increase to meet the desired value
Similar answer to interest not being greater than 0, the answer is N/A or infinite number of years, as his initial value will never increase to hit the DesiredPrincipal value
For c# this solution actually includes the dividebyZeroException that was asked
323 = 17 * 19
What will happen if Tax is not less than 1 or if interest is not greater than 0?