Repeatedly testing
selected
even after you've matched its value indicates flawed reasoning. You wouldn't do it if you were looking it up by hand, so your code shouldn't either. That's why people use the
else if
idiom. But since all your tests involve the same variable, it would make more sense to use a
switch
statement. Except the pattern is so regular that it would make even more sense to just use
Key_code = selected + 4;
as previously suggested. But this is really a code review question, which doesn't belong on this site. —
Tom Karzes 52 secs ago