Thread: How to check if A==B or C or D or E...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2008
    Location
    Vodice, Croatia
    Posts
    13

    How to check if A==B or C or D or E...

    Hello, I'd first like to introduce myself to these forums as I will most likely spend lots of time here in the future. I'm Bruno Gavranovic, aka bgavran3, I'm 14 years old and I'm pretty familiar with modding, I'm working as a level designer on 2 game modifications but I'd like to move on to more complex things, such as coding, since mapping is quite easy, anyone can do that.

    So, I've started learning C++, I pretty much learnt the basics and now I started working on some a bit more complex project.

    What I want is to get input from the user and if the input is equal to one of the words, the program responds with a text, if its not, it responds with another text.
    So the user, for example types in "hi" and the program checks if the text he typed is equal to words "hey" or "hello" or "hi". If it is, program greets him with "Hello", if the text he typed isn't equal to one of those, program responds with "What?"

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstring>
    
    using namespace std;
    
    
    int main()
    {
        char input[15];
        char answer[15];
        struct database {
            char greets;
        }
    
        database beg;
        beg.greets = "hi" && "hey";
    
        cin.getline (input, 15, '\n');
        answer[0]='\0';
        strcat (answer, beg.greets);
        if (strcmp (input, answer) == 0)
        cout<<"Hello";
        else
        cout<<"What?";
        cin.get();
    }
    But the code isn't working for some reason or another, here are list of errors CodeBlocks compiler shows to me:
    Code:
    error: 'database' does not name a type
    error: 'beg' was not declared in this scope
    I know its doable and easier using strings, by comparing string A (hi) with string B (hey), if they're not equal then comparing string A (hi) with string C (hello) and then print out the response based on this but at some point in the program development I will need to have lots of words input needs to be compared with and I want to find a way in which I'll just have to add one more word to the list to make it work.
    I'm using structures at the moment but I'm not sure are they the best way... if not, can someone point me in the right direction?

    And one more question, what is the best way to store unlimited amount of words? What I need is to get the input from the player, display an text, get the input from the player, display an text, get the input...
    And each time I want to be able to check what exactly input is, what the user has typed.

    Thanks
    Last edited by bgavran3; 07-06-2008 at 05:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 05:27 PM
  3. how to check input is decimal or not?
    By kalamram in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 07:07 PM
  4. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 11:21 PM