Hi, I was wondering how I would change the numbers 0-9 to the upper case letters A-J. I dont want to have to write a switch statement or an if else for each number, I dont know how I would do it without it.
Alphabetic characters are stored numerically, and in order.
So are numeric characters.
Therefore you can do math to translate them.
IE:
1 2 3 4 5 6 7 8 9 10 11 12
char c = '5'; // <- c is the '5' character
c -= '0'; // subtract the '0' character. Now, c is no longer the ASCII code for '5',
// but rather, is the literal number 5
c += 'A'; // add our numerical 5 to the 'A' character... giving us the 'F' character
cout << c; // prints 'F' as you'd expect
// or shorthand:
c += 'A' - '0'; // do the conversion in one step.
Alphabetic characters are stored numerically, and in order.
So are numeric characters.
This is true for practical purposes, but it isn't guaranteed to be true. We could take another approach that is guaranteed to work (and is a more general solution, although not quite so simple.)