if statement - "if" and "else if" commands are not working in c++ -


i in process of making chat bot , experimenting @ point. "if" commands not working , when enter "moodtoday" skips right else command.

(capitalization of "moodtoday" not error)

any , appreciated

#include <fstream> #include <cmath> using namespace std;   int main() {       char name[50], moodtoday[50];        cout << "a few things should know @ time..." << endl << "1. can't process last names." << endl << "2. can't process acronyms." << endl;      system("pause");      cout << endl << endl << "what name?" << endl;      cin >> name;      cout << "hello " << name << "." << endl << "how today?" << endl;      cin >> moodtoday;        //can't figure out...      if ((moodtoday == "sad") || (moodtoday == "bad") || (moodtoday == "horrible")) {          cout << "that's not good." << endl << "why feeling " << moodtoday << "today?" << endl;      }      else if (moodtoday == "good") {          cout << "great!" << endl;      }      else {          cout << "i'm sorry, don't undrestand feeling." << endl;      }        system("pause");       return 0;  } 

if you're doing c++, should using std::string , not old c-style buffers.

#include <string>  int main() {   std::string name, moodtoday; } 

c++ strings better c strings since don't have buffer overflow problems , compared ==.

also, tip, try avoid using namespace std; since can cause namespace conflicts. annoying can type std:: time make clear class or template originated , who's responsible code-wise. way own classes , templates obvious.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -