Hi,
I'm trying to write some code that will work as part of a menu system. If the user presses enter, something will happen. If they press 1, something else will happen.
To register the pressing of enter, I tried setting a variable to -1, then using "_getch()" to have the user input something- my thinking was that if the variable is still -1 afterward, then I know they pressed enter. If it's 1 then I know they pressed 1.
However, when I use "input = _getch();", and the user presses enter, input ends up as 13, and when they press 1 it also ends up as something else. I'm pretty sure I need to convert input somehow but I don't know how. I tried messing around using typecasts and atoi and it all just screwed up.
Can anyone help with this simple problem?
Code:int main() { int input = -1; input = _getch(); cout << input; return 0; }