First off, get rid of the long
if..else if...else if...
code for converting a char to an int:
if (s1[i] >= 'a' && s1[i] <= 'z')
{
digit = (int)(s1[i] - 'a') + 1;
}
Will do it.
Then sort out your indentation! At the moment that is very hard to read as the code is all over the place and it's not obvious at all.
Then extract your code for processing a string into a function which accepts a string and returns the number value - call that twice, once for each string in the same way that you have the
calculator
function.
That way, you are using the same code for processing each string.
If you still have a problem, then use the debugger to follow the code through and look at exactly what it is doing at each stage.
Yes, I could do that for you - but I don't know what you are typing as the two strings, and it's your homework! :laugh:
Give it a try - see what you can find!
If you are still stuck, come back to us and explain exactly where it goes wrong, and what values you are getting.