Char + int

This is a discussion on Char + int within the C++ Programming forums, part of the General Programming Boards category; I was wondering if there was a way to put them together. I explain: i liked the user to enter ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Location
    France
    Posts
    747

    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.
    Compiler MSVC++ 2010 with Code::Blocks.

  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
    Location
    France
    Posts
    747
    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.
    Compiler MSVC++ 2010 with Code::Blocks.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    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
    Location
    France
    Posts
    747
    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.
    Compiler MSVC++ 2010 with Code::Blocks.

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, 03: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

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