You need to understand that a character digit is not its base value. It is a printable representation of a number. So to accumulate the values of these numbers you first need to convert them to their base integral value. Fortunately with single characters it is simply a matter of subtracting the character '0' from them. So change your code to read:
the_sum += serialcode[i] - '0';
Also your
while
expression should use the length attribute of the string, rather than a fixed value:
while (i < serialcode.length())