Thread: Just started learning...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    6

    Just started learning...

    I've gone through a few of the tutorials here on the sight. I figured with my limited knowledge, I would experiment around a little bit and write my own program.

    What I'm trying to do is make a simple "conversation" program.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
       string name;
    
       cout << "***Do you know who made this program?: \n";
       cin >> name;
       if (name == "Yes" ||name== "yes" ||name== "yeah" ||name== "ya" ||name== "Yeah" ||name== "yuh huh" ||name== "Ya") {
          cout << "***Good! Let's move on then!\n";
       }
       else if (name == "No" || name == "no" ||name== "nah" ||name== "na" ||name== "Nah" ||name== "nuh uh" ||name== "Na") {
    	cout << "***Let me tell you then! Zac created it!\n";
       }
       else {
    	cout << "***The game.\n";
       }
    
        string theirname;
    
        cout << "\n";
        cout << "***So what is your name? \n ";
        cin >> theirname;
        if (theirname == "Anything") {
            cout << "***Well, nice to meet you, "+theirname+". I am your computer!\n";
        }
        else if (theirname == "Miranda" ||theirname== "miranda") {
           cout << "***Oh, my! It's the love of Zac's life -- Miranda!\n";
        }
        else {
           cout << "***Well, nice to meet you, "+theirname+". I am your computer!\n"; 
        }
    }
    Now I know this may look pretty bad (like I said, I'm just learning on my own). The problem I'm having is in the "if" and "else if" responses. I was trying to cover as many possible inputs as I could think of, which is why there is "yeah," "yuh huh," "Ya," etc.

    The problem arises when one of the inputs has a space in it. The program is reading the second word as the input for the next question. For example, when I do this as a test...

    ***Do you know who made this program?
    yuh huh
    ***The game
    ***Well, nice to meet you, huh. I am your computer!


    So how can I stop it from doing this? It does it for every input that has a space.




    Also, is there a command that makes the program recognize a specific keyword from an input? For instance, if I wanted the program to say the same thing for every string that has the keyword "apples" in it...

    ***What is your favorite food?
    I like apples!
    ***I like apples too!

    or

    ***What is your favorite food?
    I enjoy consuming copious amounts of apples!
    ***I like apples too!



    Thanks for any help in advance!

    Edit: And if it makes any difference, I'm using Code Blocks and the GNU GCC compiler.
    Last edited by Ignoramus; 12-07-2009 at 09:24 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is learning C/C++ worth it?
    By C/C++ Learner in forum A Brief History of Cprogramming.com
    Replies: 44
    Last Post: 11-05-2008, 03:55 PM
  2. Best Approach for Learning
    By UCnLA in forum C Programming
    Replies: 5
    Last Post: 03-21-2008, 02:35 AM
  3. Advice for learning C without a teacher
    By tvsinesperanto in forum C Programming
    Replies: 10
    Last Post: 03-16-2006, 04:05 PM
  4. Need Help On a Simple Bank Program
    By oobootsy1 in forum C# Programming
    Replies: 9
    Last Post: 08-08-2005, 10:51 AM
  5. Need help getting started
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2001, 11:08 PM