continuous input?

This is a discussion on continuous input? within the C Programming forums, part of the General Programming Boards category; I am looking to make a program that allows for individual keys to be used as a running tally (like ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    4

    Question continuous input?

    I am looking to make a program that allows for individual keys to be used as a running tally (like the 'K' key is the integer '5') that continuously adds each integer, like if you press k, then immediately press k again, it will display 10. However, having almost no coding background, I would like to know if this is possible, and if so, how?

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Not easily, and not with standard C.

    You'll need to use libraries.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    4
    what about C++?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Same.

  5. #5
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Use a library. For Linux, ncurses, I guess, for Windows, Win32. Or write a library that provides a common interface for both, but uses the two systems respective libs.

  6. #6
    Registered User
    Join Date
    Jul 2010
    Posts
    4
    what about a way to just bypass enter. Like a do while loop. Like in this program
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int a,b,
      cout<<"Please pick a number: ";
      cin>> a;
      cin.ignore();
      cout<<"you chose "<< a <<" your total is "<< a;
      cin.ignore();
      cout<<"Please pick another number: ";
      cin>> b;
      cin.ignore();
      cout<<"you chose "<< b <<" your total is "<< a + b;
      cin.ignore();
    but put something in there for a, that if a is not return, run this part again
    Code:
      int a,b,
      cout<<"Please pick a number: ";
      cin>> a;
      cin.ignore();
      cout<<"you chose "<< a <<" your total is "<< a;
      cin.ignore();
    and when it is enter, end the program.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Code:
    cin >> a;
    won't return until you press enter.

  8. #8
    Registered User
    Join Date
    Jul 2010
    Posts
    4
    Quote Originally Posted by cyberfish View Post
    Code:
    cin >> a;
    won't return until you press enter.

    what can I replace cin with though?

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There's no standard function to take keystrokes. You will need something OS + compiler specific, as mentioned above.


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Not without pressing the enter key each time. Like User Name: said, use ncurses for Linux and Win32 for Windows.

  11. #11
    Registered User
    Join Date
    Jun 2010
    Posts
    182
    Quote Originally Posted by Babkockdood View Post
    Not without pressing the enter key each time. Like User Name: said, use ncurses for Linux and Win32 for Windows.
    ncurses are the same of pdcurses or are different versions of libraries doing similar things?

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Same sort of thing, different implementations.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing integer input into string, wrong value
    By Ace2187 in forum C Programming
    Replies: 3
    Last Post: 11-14-2009, 01:28 AM
  2. Allocating input to an array
    By ij.cohen in forum C Programming
    Replies: 2
    Last Post: 10-12-2009, 10:48 AM
  3. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  4. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  5. Simple Console Input for Beginners
    By jlou in forum C++ Programming
    Replies: 0
    Last Post: 06-21-2005, 01:50 PM

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