How to Make the Console respond to Statements containing specific Characters

I want to know how a Console can respond in a Specific manner when the answer contains a specific character/words.
For example, If the Console asks: "How are you?" and the Response includes "Good" in the sentence, The Answer is different than when it includes "bad".
I tried using the Switch Function but I learnt it can only deal with integers. Then I went on to try the if Function:

1
2
3
4
5
6
7
8
9
10
  string FeelingResponse;

    cout << "\nHow are you feeling?" << endl;
    cin >> FeelingResponse;

   if (FeelingResponse == "Good")
			{

			     cout << "I'm Glad!" << endl;
			}


At the Moment, It only replies when the answer is 'Good'. My question is, how can it respond like this when the answer CONTAINS 'good'.

Thank you in advance.
You can use the string member function find

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

int main()
{
  string response;
  cout << "How was your day?" << endl;
  getline(cin, response); // To accept white spaces like "I had a good day"
  // http://www.cplusplus.com/reference/string/string/find/
  // http://www.cplusplus.com/reference/string/string/npos/
  if(response.find("good") != string::npos){ // If you rather not use string::npos, you can do (!= -1)
    cout << "That's great to hear!" << endl;    
  }
  else{
   cout << "Hope you have a better day!" << endl;   
  }
  return 0;
}
That worked like a Charm! Thank you very much .
> That worked like a Charm!

Now consider these:

Q: How was your day?
A: Not so good.

Q: How was your day?
A: It could have been good; but it wasn't.
Topic archived. No new replies allowed.