just a simple question

This is a discussion on just a simple question within the C++ Programming forums, part of the General Programming Boards category; Does anyone know how to get the input of a user without them haveing to press enter after they are ...

  1. #1
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148

    Unhappy just a simple question

    Does anyone know how to get the input of a user without them haveing to press enter after they are finished..

    for example:

    1. Go home
    2. Get Drunk
    3. Get layed
    >>3

    and then immidiatly after the user presses 1,2 or 3 it goes to that option

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    8
    int choice;

    cin >> choice;

    switch (choice)
    {
    case 1:
    cout << "you went home";

    case 2:
    cout << "you got drunk";

    case 3:
    cout << "you got laid";

    default:
    cout << "invalid choice";
    }

  3. #3
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    that wouldn't work you would still have to press enter after the user type's a number to put it into choise.
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

  4. #4
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    char option = getch();

    if (option =='1')
    {
    cout<<"you got drunk with a ferret called pete";
    }

    if (option == '2')
    {
    cout<<"you went home with pete the ferret";
    }

    if (option == '3')
    {
    cout<<"you and pete the ferret ...";
    }
    Monday - what a way to spend a seventh of your life

  5. #5
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    thanx it works
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 09:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2005, 12:41 AM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21