i'm not sure how to do this, but i know it's not labels.

from what i've read, labels are used with goto, and goto is that weird cousin we stay away from.

what i'd like to do is assign keywords to text, and when one of those keywords is typed in, the program would print any text with that keyword.

as an example, i have oranges, lemons, peaches, and bananas. my keywords would be sweet, citrus, orange, and yellow. they'd be organized in this sort of fashion:

oranges - citrus, orange
lemons - citrus, yellow
peaches - sweet, orange
bananas - sweet, yellow

so, if i typed 'yellow', the program would tell me 'bananas, lemons'. if i typed citrus, the program would tell me 'lemons, oranges'. if i typed in 'orange sweet', the program would tell me 'peaches'.

i'm not asking you to code this out for me. my program is going to have more than four keywords, and some items of text will have more associated keywords than others. i just don't have the first idea how to start this, and i'm not sure what to look for, as i'm self-taught and fairly novice. a point in the right direction would be great!
Either use a bunch of if-if else 's, or a switch statement.


If-else is the first thing described on that page, switch statements are at the bottom. Switch would probably be more concise.
By text do you mean strings or character arrays, or class objects? The method of solving your problem depends upon this.

As DonGato already described, if-else or switches is probably the most intuitive and easiest way to solve this problem if you are working with strings and character arrays.
Create a "Fruit" class with an array of your keywords. You could use an enumerator to associate a numerical value with your keywords.

Last edited on
@illusionist - by text, i mean strings, but it'd be something that i'd cout when prompted, (ie: Hello, world!).

thanks everyone for the input! i'm going to look into all these options. my final product is probably going to have between twenty and thirty keywords. it's essentially going to be a "search engine" for a catalogue of different entries. i'm building an rpg, and i'm using this to sort abilities based on keywords (fire, ranged, cc, passive, etc). i'll probably have to employ an and gate somewhere, because if i type in three keywords, i want it to print entries that have all three keywords.
Topic archived. No new replies allowed.