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.
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.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"; } }
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.