so i wrote this small piece of code. it simply waits for the user to enter a command, and then, depending on the command, a different message appears. when i enter the simple words like debug and execute, it does what i want it to do. now, when i try to use the load filename command, my display does not accept the input and my "invalid entry" message appears. what am i doing wrong?
thank you.

#include<iostream>
#include<string>
using namespace std;

int main()
{
    
    
    string command; 
   
    cout << "Welcome to the Intrepeter!" << endl;
    cout << " Please feel free to enter a command." << endl;
    cin >> command;
    
    
    if (command == "load filename")
      {
          cout << " load the specified file\n";
      }
    else if (command == "execute")
      {
         cout << " execute the program\n";
     
      }
    else if (command == "debug")
      {
         cout << "debug mode\n";
      } 
     
    else if (command == "assemble filename")
      {
         cout << "will assemble \n";
     
      }
      
    else if (command != "load filename" || "execute" || "debug" || "assemble filename")
       {
             cout << "Invalid Entry\n";
             cout << "Please your correct terms\n";
       }

      
       
       while(true){}
       return 0;   
}

what difference do you see between:
execute
debug
load filename
asseble filename
The first two are one word commands and the latter two are two word commands, right?
Unfortunately the >> operator only works for single word commands. Actually >> will stop input with the first whitespace char encountered, which in the case of your two word command is the space between the two words. Use getline() instead of >> and everything should be fine.

In addition to what Lerner posted, are you allowed to use switch statements instead of multiple if/else?

It would make the code easier to read

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.