Thread: Possible?

  1. #1
    Banned
    Join Date
    May 2004
    Posts
    55

    Possible?

    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?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    depends on the implementation. what OS/compiler are you using?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    #include "conio.h" --non standard

    getch(); //doesnt echo to the screen
    getche(); // echos to the screen
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  4. #4
    Banned
    Join Date
    May 2004
    Posts
    55
    Quote Originally Posted by Sebastiani
    depends on the implementation. what OS/compiler are you using?
    I'm using Dev-C++,

    It didn't worked manofsteel >.< I need a code so I can make an input without pressing ENTER, thanks for help anybody
    Last edited by Noxir; 08-06-2004 at 05:24 PM.

  5. #5
    C++ n00bie :D
    Join Date
    Jul 2004
    Posts
    63
    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();

  6. #6
    Banned
    Join Date
    May 2004
    Posts
    55
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main ()
    {
        int x;
        x=getche();
        cout << "1+1=";
        cin>>x;
        system("PAUSE");
    }
    Now the problem is, that when I start this program the "1+1=" comes after I've pressed a button, any ideas? x_X

  7. #7
    C++ n00bie :D
    Join Date
    Jul 2004
    Posts
    63
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main ()
    {
        int x;
        cout << "1+1=";
        x=getche();
        system("PAUSE");
        return 0;
    }
    getche() and getch() act like their own input, so you dont need cin

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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).

  9. #9
    Banned
    Join Date
    May 2004
    Posts
    55
    Thnks all

Popular pages Recent additions subscribe to a feed