handling user input

This is a discussion on handling user input within the C++ Programming forums, part of the General Programming Boards category; I am trying to figure out how to receive and handle user input in c++? If i want the user ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266

    handling user input

    I am trying to figure out how to receive and handle user input in c++?


    If i want the user to enter input like this, line by line
    Code:
    1 10
    44 233
    how can I take each of these values and store them..so i can work with them.?
    (ie. so i can place them into a function that takes (int a, int b))

    I want to start practicing with online judge but I cant quite get the hold of taking user input
    Last edited by rodrigorules; 11-11-2009 at 09:52 PM.

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Study about std::cin you will get to know

    and for storing data read about data types and variables

    and about displaying data read about std::cout

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Declare some variables of the proper type, and "cin" into them.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    even if their on the same line?

    the input will be not be inputed by me, it will be inputted LINE BY LINE by an online evaluator.

    so my code must be able to understand when i type in "1 10" enter "100 200"
    Sample Input

    1 10
    100 200
    201 210
    900 1000


    I will post my initial attempt

    Code:
    int main()
    {
    int nums[8];
    for(int i =0 ;i < 8; ++i)
    {
            cin>>nums[i];
    }
    O wait, it worked...I am guessing that the space in the between the numbers doesn't even matter.
    Last edited by rodrigorules; 11-11-2009 at 10:04 PM.

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Correct. When getting numbers from the input, whitespace is ignored.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. displaying text below user input (cin)
    By MilkyJoe in forum C++ Programming
    Replies: 4
    Last Post: 10-18-2009, 04:00 PM
  2. Replies: 4
    Last Post: 08-31-2009, 12:04 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 12:09 PM
  4. Ending user input with # character
    By jowatkins in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2004, 11:41 AM
  5. Handling User Input
    By wcfbv in forum C Programming
    Replies: 3
    Last Post: 11-20-2002, 07:35 AM

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