Reputation: 21
I want to add the character ‘4’ and the digit 3 and have it equal 7 without any library methods if possible I.e ‘4’ + 3 = 7
Upvotes: 2
Views: 151
Reputation: 814
For all single digits you can do like:
char c = '4';
// If you want to add 3 now you can do like:
int result = c - '0' + 3;
Subtracting '0' is the key here. That's it
Upvotes: 11