C++ keypress recognition - help needed

Associate
Joined
30 Aug 2004
Posts
831
Location
Sheffield
hi all,

i'm pretty new to c++, i'm just writing console applications at the minute.

basically my app sets the hours and minutes of a digital clock, however i want the app to ask the following question,

"Enable 24hour mode? [Y/N]"

i want the user to only be able to enter either Y or N? is it possible to check the input (using cin) without the user actually having to press return?

this is for an assignment, so i have to use standard c++, and thus far i haven't found any way to checking it using only standard c++ code :rolleyes:

cheers,

munkey
 
Not sure there is without system dependent functions. Why not just validate the input after they press enter, and if it's not valid, ask again?
 
hmmm

#include <conio.h>

while(whatever){
char key;

if (kbhit()){
// get keyboard data, and filter it
key = toupper(getch());

if (key=='Y'){
do something;
}else if (key=='N'){
do something else;
}else{}
}
}

Might work....
 
Last edited:
Back
Top Bottom