Thread: Char + int

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    Char + int

    I was wondering if there was a way to put them together.

    I explain: i liked the user to enter a coordinate like a1.
    But in cin>> x; x must declared a char or a int.
    Isn't there a trick to come around this? I want to avoid to ask the user two times.
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    What about:
    Code:
    char c;
    int n;
    cin >> c >> n;

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Great! Thanks a lot EVOEx!

    But he still has to push "Enter" two times.

    It would be good if i could do the same with only one "Enter".
    Last edited by Ducky; 03-28-2009 at 06:34 AM.
    Using Windows 10 with Code Blocks and MingW.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No he doesn't. What gives you that idea?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    You're right it works with a 'char' and an 'int' but not with two 'int's.

    I was trying with two int's first.

    Sorry and thanks.
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM