function to calculate and append check digit