Accepting Multiple Types of Input

This is a discussion on Accepting Multiple Types of Input within the C++ Programming forums, part of the General Programming Boards category; Hello guys, well i just started making a Periodic Table Program. It is going to have an actual display of ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    Accepting Multiple Types of Input

    Hello guys, well i just started making a Periodic Table Program. It is going to have an actual display of the table (text based for now), and it will also have you be able to look up an element from the Name (ex: Hydrogen), Symbol (H), or Element Number (1). Which is where i am finding a small problem.

    Before i go into that i will just finish outlining the program. It also will have a help bit, and a function that does some Molar Calculations and other useful quantum calculations.

    Back to the problem...

    How can i get my program to work like this?

    Lookup Element:

    When it says that i want it to be able to take in either the number, symbol or name and look that up.

    Now i think i know how i am going to go about looking up the actual info, but i dont know how to get that to take in 3 different types of information and differentiate between them.

    I tried storing it into an array temporarily and then have it sort it out from there and have it transfer the information. However i couldnt get that to work either.

    Thanks guys!
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,598
    Have 3 different functions, or possibly overload the function for each of the search types.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Read them all as strings, then use std::map as a lookup table. Register the strings "Hydrogen", "H" and "1" to point at the same element (probably stored in an std::vector or something).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  2. accepting input while writing to screen
    By variable in forum C Programming
    Replies: 17
    Last Post: 02-06-2005, 09:14 PM
  3. multiple input type
    By modec in forum C Programming
    Replies: 5
    Last Post: 11-23-2004, 11:53 PM
  4. Differentiating Between Different Input Types
    By lexxonnet in forum C++ Programming
    Replies: 6
    Last Post: 07-27-2003, 02:20 AM
  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