954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Question about accounting program

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"

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

Have you got Dev-cpp?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Yes, that is what I am using.

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
Then you need the header file #include <conio.h> and it is getch()

Yep that worked. Thanks!

Shadoninja
Light Poster
37 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You