I know that to make a simple yes or no question I can do this:

int Answer;
cin >> Answer;
if (Answer == 1)
{
Response
}
else
{
Response
}

But in the accounting program (In a recent thread), it registered the key before you hit enter.

What code do you have to add/change to make this program to respond instantly after you give a certain input? (pushing 1 and getting the response without having to hit "enter"

Recommended Answers

All 6 Replies

Member Avatar for iamthwee

Maybe use getch() or something equivalent, however, that has portability issues.

Thats what I thought but I can't seem to get any good information on it.

I tried using the source from the program I first saw this command in and it is set up like this:

char ans;
ans=_getch()

but that does not work in my code

Member Avatar for iamthwee

Have you got Dev-cpp?

Yes, that is what I am using.

Member Avatar for iamthwee

Then you need the header file #include <conio.h> and it is getch()

Then you need the header file #include <conio.h> and it is getch()

Yep that worked. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.