Originally Posted by spikeymike
The bit in orange... code works, tried it before posting.
Actually it doesn't, not really.
I hadn't noticed that aChar was an int (nice choice of variable name - this is why I
hate naming schemes that include the variable type).
So you're not actually doing what was asked - the input is being interpreted as decimal - you're not actually doing anything based on the value of the
characters entered. (To be clear, the OP has a variable aChar of type char. If you were to write "int aInt = aChar;" and then "if (aInt >=0 && aInt <=9) ..." you'd get the wrong result).
If you enter 10, it won't say OK, which I very much doubt is the desired outcome.
Also, if the user
doesn't enter an digit, then aChar doesn't get written to, so you're left with what ever was in there before.
So it *can* still say OK even if you don't enter a digit. (Try initialising aChar to 5 before the call to cin to see this happen).
The bit in bold... I doubt very much that would work. I've always used ASCII if I'm validating a letter.
It works fine (aChar has to be a char, (or an int created by casting a char to an int)) of course. It's arguably more portable, although it still goes horribly wrong for something like EBCDIC where the alphabet isn't a single contiguous range.