Explanation of the Solution | Minimum Pay for Credit Card
2. Katas
To see full version of Solution visit GitHub. See below↓
Solution:
- Create a function that takes two variables.
-
We pass to a part of the help variables:
- start_balance - to duplicate the outstanding balance, later it will come in handy.
- minPay - the minimum payment at the moment, can and will approach ;)
- count - for the number of attempts for which the program has found the minimum payment.
-
We pass to the main part of the program:
- We will use the cycle while, since we do not know how many attempts we will need.
-
Help variables in the cycle itself:
- month - zero the month to the starting value.
- OutStandingBalance - zero the outstanding balance to the starting value.
- count - add 1 to the number of attempts.
- We apply the algorithm that we disassembled in the Example to calculate the outstanding balance after the year of payment by only a minimum payment.
-
We check the outstanding balance after one year:
- ЕIf it is equal to or less than 0, then this means that minPay is matched correctly and we return a string by condition
- In other cases, adds minPay 10 and start 3 point again.
That's all.
If you liked Katas, you can put star on this repositories, this will motivate me to write similar Katas for you.
Visit Github page: