Thread: Accepting Multiple Types of Input

  1. #1
    Registered User
    Join Date
    Nov 2004

    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
    Have 3 different functions, or possibly overload the function for each of the search types.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    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).

    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, 02:20 PM
  2. accepting input while writing to screen
    By variable in forum C Programming
    Replies: 17
    Last Post: 02-06-2005, 10:14 PM
  3. multiple input type
    By modec in forum C Programming
    Replies: 5
    Last Post: 11-24-2004, 12:53 AM
  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