{
//Program Goal
//Have 3 Strings to represent 3 categories
//Have the user type in their name
//Have the user type in a full sentence how they are feeling
//Program should find the word in the user inputted sentence and display an appropriate response
//Error that I'm having currently... It seems to go through the loop twice
//and that it displays the wrong word first.
string name;
std::string feeling;
/*std::string str1 ("fine" "decent");*/
std::string str1[2] = {"fine", "decent"};
std::string str2[2] = {"bad", "horrible"};
std::string str3[1] = {"good"};
std::string words = "";
int i = 0;
cout<<"Input your name: ",
getline (cin,name);
cout<<"\nHello "<< name <<"\n"<< endl;
//asking
cout<<"How are you feeling today?? ",
getline (cin,feeling);
//finding the word in string 1
std::size_t found = feeling.find(str1[2]);
//finding the word in string 2
std::size_t found2 = feeling.find(str2[2]);
//finding the word in string 3
std::size_t found3 = feeling.find(str3[1]);
if (found=std::string::npos)
for (int i= 0; i < 2; i++)
std::cout <<"\n\nI'm glad you are feeling " << str1[i]<< " "<< name << "."<< "\n\n";
else
if (found2=std::string::npos)
for (int i= 0; i < 2; i++)
std::cout << "\n\nI'm sorry that you are feeling " << (str2[i])<< " "<< name <<"."<< "\n\n";
else
if (found3=std::string::npos)
for (int i= 0; i < 2; i++)
std::cout << "\n\nI'm glad you are feeling " << (str3[i])<< " "<< name <<"."<< "\n\n";
return 0;
}
//Results on Screen
//Why does this display twice and how can I fix this?
//Input your name: john
//
//Hello john
//
//How are you feeling today?? I'm feeling decent today
//
//
//I'm glad you are feeling fine john.
//
//
//
//I'm glad you are feeling decent john.
//
//Press any key to continue . . .