Thread: if i press enter

  1. #1
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    Exclamation if i press enter

    I have a problem. I have a do while loop that go on foever. I want to stop it by pressing the enter button with out typing any input. How do i write the if statement ??
    :0
    The one & only!!

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    It's not standard, but you could try kbhit() (or _kbhit() or
    __kbhit()!, depending on your compiler) which is in conio.h.

    If it's in Windows then you could try checking GetAsyncKeyState()
    during it iteration of the loop.

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    Code:
    do
    {
        if(kbhit())
        {
            keypress=_getch();
            if(keypress==13)
                break;
        }
    }while(whatever);

  4. #4
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    still having trouble

    I get an error when i input the code:

    error C2065: 'keypress' : undeclared identifier
    Error executing cl.exe.

    do
    {
    cout << endl
    << "Enter employee last name: ";
    cin >> lastname[count];

    cout << endl
    << "Enter ssn: ";
    cin >> ssn[count];

    count++;
    if(kbhit())
    {

    keypress=_getch();
    if(keypress==13)
    break;
    }


    } while (count < 50);

    //Maximum employees is full
    if (count == 50)
    cout << endl << "Maximum employees for database is reached." << endl;


    system ("CLS");
    The one & only!!

  5. #5
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    i was just making up a variable name. first you must declare it:

    int keypress;

  6. #6
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    still not working

    ok the program is executeable BUT
    when i press enter nothing happens. it doesnt clear the screen & take me to the report screen?
    The one & only!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  2. Newbie Help: Currency Converter
    By Ashfury in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 01:21 PM
  3. Capture Enter key press in EDIT Box
    By richiev in forum Windows Programming
    Replies: 4
    Last Post: 07-14-2005, 12:03 AM
  4. Einstine calculator Mark 2
    By Mach_ie in forum C Programming
    Replies: 1
    Last Post: 08-31-2003, 01:54 PM
  5. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2003, 12:23 AM