Differentiating Between Different Input Types

This is a discussion on Differentiating Between Different Input Types within the C++ Programming forums, part of the General Programming Boards category; Hey there! I have a slight problem with C++. I looked through the boards and tutorials here, but wasn't able ...

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

    Differentiating Between Different Input Types

    Hey there!
    I have a slight problem with C++. I looked through the boards and tutorials here, but wasn't able to find a solution... so here goes..

    I need to read in from a part of a file, which looks somewhat like this

    1
    A F3 10 F2 5 F4 6
    B F1 15 F5 12 F6 9
    C F1 10
    2
    D F1 10
    E F1 10
    F F1 10

    where 1 is a representation of the first minute, and A, B, and C are customers in a queue. 2 is the next minute.

    I've been trying to store the information in an array like this.

    data[minute][customer][F*][number]

    so for the first minute:

    data[1]['A'][3][10]
    data[1]['A'][2][5]
    data[1]['A'][4][6]


    however, I have been unable to find a method of reading in each minute individually, as I dont have a check condtion to figure out if the variable i'm reading in is an integer or a character.

    now that thats over.... the question...

    Is there any way to determine if input is an integer or character? or is there a more efficient way of storing these minutes?

    Thanks in advance
    Abhinay
    Last edited by lexxonnet; 07-27-2003 at 01:35 AM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    This might help you determine if input is a number or not.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I agree with funkydude.

    Just out of curiosity, what does the data for each customer represent?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    4
    thanx funkydude. I actually figured out another method. using the input.peek() function, and entering it into a temporary integer variable, when enteraing a character, it enters zero, while for a number, it is the number itself. As long as there isn't a zero minute, it should work. This however, leads to another problem.

    When storing things in an array, I need an array as illustrated in my first post.

    data[minute][customer][F*][number]

    but the problem is apparent. I cant store characters and integers in the same array. Originally, i was intending to store the character as an ASCII integer, and then convert it later, but i'm not too sure about how to do this either

    And btw... bennyandthejets, F1, F2 etc stand for different items, and the number next to them, the number of such items the customer wants to order

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    4
    okie... i figured out the answer to my other question in faq's as well... thanx for the help!

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    My advice is to move to classes. What you're describing is best done with classes. Here's an example:

    Code:
    class Customer
    {
    public:
    item *items;
    char *id;
    };
    
    class Item
    {
    public:
    char *name;
    int quantity;
    };
    
    Customer custA;
    custA.id="Joe Bloggs";
    Item jItems[3];
    custA.items=&jItems;
    Catch my drift? I know it's a bad example, but you can't expect me to work out the complete structure for you. Basically, you have a structure for customers, and a structure for items.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    4
    thanx for the suggestion. I was planning to use classes, but was trying to get my input working first

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  2. Help with ! (NOT)
    By Skarjak in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2005, 07:25 PM
  3. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM
  4. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM
  5. reading input files with different types of data
    By sanu in forum C++ Programming
    Replies: 4
    Last Post: 06-27-2002, 08:15 AM

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