Would really appreciate if anyone could help me with this as I am new to C++.
I am trying to write a program that uses a while loop to keep looping until the player
presses ‘q’ key or the escape Key. The program is to display some type of functionality to the
user and allow them to enter in some text and/or numbers and display this to screen.
The problem I have is that when I wrote the code it first asks the user to get the key and then if the key is pressed it will go to the frame where the user can input a word or number and then the process will repeat. So it's basically stepping through the process frame by frame when I want it so that no matter when u press 'q' or the ESC key it will end the program.
I have scoured google for some information but it has not really helped. How do I make it so that even while the user can type, if the user its 'q' or the ESC key the program will end?
#include <iostream>
Help leading me towards the solution would be much appreciated so I could learn rather than a full answer :)
while (!iclose)
{
iclose = _getch();
if (iclose == 51 || VK_ESCAPE)
{
_getch();
system("END");
}
else
{
cout << "Press ESC or Q to exit" << endl;
cout << "Put in a number and I will tell you what you typed: ";
cin >> cnumber;
system("CLS");
cout << "your number was: " << cnumber << endl;
}
}
I understand that the reason it's probably doing this is because I am asking the 'if' to get the key first. But I am still stuck as to if I am on the right track or not.
while (cclose)
{
if (GetAsyncKeyState(VK_ESCAPE))
{
cclose = false;
}
else
{
cout << "Press ESC or Q to exit" << endl;
cout << "Put in a number and I will tell you what you typed: ";
cin >> cnumber;
system("CLS");
cout << "your number was: " << cnumber << endl;
cclose = true;
}