I have the following code that validates if a certain digits is valid using luhn algorithm module 10. I need another function that generates the next check-digit actually by giving four digit number so the 5th digit would be next digit checksum. Answer By modifying the current function to this one I was able to get next checkdigit: