Press "esc" to stop asking for values

Apr 29, 2021 at 1:32pm
Hi i'm new here.

I want to make a c++ program that will ask values that can be stored in an array and when the user press "esc" the program will stop asking for the values and the program will identify the largest and smallest value stored in the said array.

I'm using windows.


Help me please.
Last edited on Apr 30, 2021 at 5:15am
Apr 29, 2021 at 1:51pm
Hello DracoL1ch,

The first thing you need to do is help your-self by mentioning what operating system you are using and what IDE yo arr using.


There is no point to getting suggestions that only work for Windows if you are using something else.

Andy
Apr 29, 2021 at 4:45pm
esc key can be tricky to trap. its doable, but its not as easy as pressing 'x'. does it HAVE to be esc?
Apr 29, 2021 at 5:29pm
If this is windows, then you need to use _getch() from #include <conio.h> which is non-standard. This obtains the entered char without also requiring a following \n.

Standard C++ has no mechanism to obtain a single char without a \n being also entered.

Apr 30, 2021 at 5:08am
I'm using windows. This is a part of my exam and I don't know how to make this one, I'm Blank for this one. Thank you for all of your reply. I will explore more the Dev C++. Btw. I'm not a computer programmer that's why it's hard for me.
Apr 30, 2021 at 5:14am
@jonnin
Yes sir, it has to be an esc that's why I'm having trouble with it.
Apr 30, 2021 at 8:41am
For Windows, _getch() will get one char entered from the keyboard. The value for ESC is the decimal 27. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getch-getwch?view=msvc-160
Apr 30, 2021 at 3:44pm
For some reason I was thinking escape emitted 2 characters instead of just a 27 and was thinking to use the 'keypress'/ virtual keys tools on it which is more aggravation. Thankfully looks like 27 is good to go.
Topic archived. No new replies allowed.