-
press ESCAPE to exit
hi
my program is a tollbooth my program is working i just want to know if want to terminate my program using ESCAPE key what should i as it is a funtion key
here is my code
Code:
# include <iostream>
# include <conio.h>
using namespace std;
class tollbooth
{
private:
long int total_cars;
float total_cash;
public:
void payingcar()//inline function
{
total_cars++;
total_cash=total_cash+0.50;
}//end of function
void nonpayingcar()//inline function
{
total_cars++;
}//end function
void print () //inline function
{
cout<<"total cars passed:"<<total_cars<<endl;
cout<<"total cash received:"<<total_cash<<endl;
}//end function
tollbooth ()
{
total_cars=0;
total_cash=0;
}//end constructor
};//end class
int main ()
{
tollbooth lahore;
char push_key;
cin>>push_key;
do
{
if (push_key=='1')
{
lahore.payingcar();
}//end if
if (push_key=='0')
{
lahore.nonpayingcar();
}//end else
cin>>push_key;
}//end do
while (push_key!='@');
lahore.print ();
getch ();
}//end main
here i have used '@' key to get out from loop
-
You can capture it with getch(). As escape is a function key, there is a functional part (to distinguish it from other keys) and the escape part. Then you just compare that to whatever escape is on the system and you can branch to a return statement to quit.
You could also capture it with buffered input as in cin>> , but the buffering may change what you are looking for. To take an example from another function key, you could capture an enter key with getch() too. You might get CRLF (carriage return, line feed -- /c/r) on windows. But in buffered input the sequence is mashed to \n (newline).
As for what escape is on your system, or the computers you want to support, I don't remember. Try setting up a simple input routine and debugging for a while to see the actual keys.