>> Isn't there a function for converting a single char to an int?
No. There really isn't any need for it anyway, since writing it out is so simple and always works.
>> Or couldn't i just cast the char to an int? Would that help?
No, casting to an int would provide the character code for the digit, not the actual number itself. An implicit cast is what was done automatically in your original code that was causing the problem.