-
Exiting Programs
[gloworange]How do i tell the computer to exit the program when Q and enter is pressed. I just started writing in it and i want to know how. I have tried giving it a command line saying close screen and window and program when those to are pressed but nothing works. Help me please :) [/gloworange]
i wrote it in C++
-
does it absolutely have to be when q AND enter are pressed?
if this is from a menu, or switch statment, you could use "exit(0);" without the quotes.
if you want a process to repeat until a key is pressed, you could #include <conio.h> and then do something like,
while( !_kbhit() ) {
do this;
};
or
for( ;; ) {
do this;
if( _kbhit() ) exit(0) ;
}
the switch statment might look like,
switch ( variable ) {
case '1' : whatever ;
break ;
case 'q' : exit(0) ;
break ;
default : exit(1) ; // where the "1" means that an error has occured.
}
once again, im not sure about two keys being pressed together to trigger an event. but perhaps if you are more specific with your problem then you will find answers.
hand.
-
Exiting Programs
I mean type in a key then press enter to make it go through to make the program end