Is it possible to do so when you make a input you don't need to push enter?
like "1+1="
then you just press 2 and it outputs "right!" for an example
if it works, then how?
Printable View
Is it possible to do so when you make a input you don't need to push enter?
like "1+1="
then you just press 2 and it outputs "right!" for an example
if it works, then how?
depends on the implementation. what OS/compiler are you using?
#include "conio.h" --non standard
getch(); //doesnt echo to the screen
getche(); // echos to the screen
I'm using Dev-C++,Quote:
Originally Posted by Sebastiani
It didn't worked manofsteel >.< I need a code so I can make an input without pressing ENTER, thanks for help anybody
They do, echo means that it shows what you pressed. If you use getch(), then you wont see the input, just the "Your right!", aslong as you put the if statement after checking it, that is. getche() will show what you typed, so it is most likely what you want. To get them to work, use it like declaring a variable:
Code:input=getche();
Now the problem is, that when I start this program the "1+1=" comes after I've pressed a button, any ideas? x_XCode:#include <iostream.h>
#include <conio.h>
int main ()
{
int x;
x=getche();
cout << "1+1=";
cin>>x;
system("PAUSE");
}
getche() and getch() act like their own input, so you dont need cinCode:#include <iostream.h>
#include <conio.h>
int main ()
{
int x;
cout << "1+1=";
x=getche();
system("PAUSE");
return 0;
}
By setting x equal to getch, it runs the getch function and places whatever the result is (i.e. the button you pressed, in x).
Thnks all :D