Thread: handling user input

  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
    Chappell Hill, Texas
    Posts
    2,332
    Declare some variables of the proper type, and "cin" into them.
    Mainframe assembler programmer by trade. C coder when I can.

  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
    Chappell Hill, Texas
    Posts
    2,332
    Correct. When getting numbers from the input, whitespace is ignored.
    Mainframe assembler programmer by trade. C coder when I can.

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, 03:00 PM
  2. Replies: 4
    Last Post: 08-31-2009, 11:04 AM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  4. Ending user input with # character
    By jowatkins in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2004, 10:41 AM
  5. Handling User Input
    By wcfbv in forum C Programming
    Replies: 3
    Last Post: 11-20-2002, 07:35 AM