use esc to call a function

Hi;

I'm writing a program and required to give output when esc is pressed. How would I do this?

Note: I'm still new to C++and right now I am studding OBJECT ORIENTATION PROGRAMMING.
It depends on your operating system and terminal. What operating system are you using?
You may want to look at this: http://www.cplusplus.com/forum/general/70775/
This is a simple program of adding two numbers. ESC is used to call the function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <conio.h>

using namespace std;

double addthis(double,double);   // Function Prototype
int main()
{
	double a,b;
	double store=0;
	int z=27;

	cout << "Enter the first number: ";
	cin >> a;

	cout << "Enter the second number: ";
	cin >> b;

		while (getch()== static_cast<char>(z))
		{
			store=addthis(a,b);		// Function Calling
			cout << "After adding both numbers: " << store << endl;
		}

	cout << "You didn't press ESC..." << endl;

	system ("pause");


}

double addthis(double a, double b)	// Function Definition
{
	return a+b;
}



The ASCII value of ESC key is 27. I converted 27 to its character form, which is basically ESC key... And then i put the while condition on it.

Works fine using Visual Studio and Dev C++ compilers...
Topic archived. No new replies allowed.