void Code::AppendCheckSum() // postcondition: if IsValid() then myLength is updated and // myChars contains the original characters followed // by a dash and the appropriate checksum; otherwise // myLength and myChars are unchanged { if (IsValid()) { int k; int sum = 0; int len = Length(); // could use myLength here too for(k=0; k < len; k++) { if (isdigit(myChars[k])) { sum += digitToInt(myChars[k]); } } myChars[myLength] = '-'; myChars[myLength+1] = intToDigit(sum % 10); myLength += 2; } }