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.

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

       return 0;   
7 Years
Discussion Span
Last Post by Vllinator

what difference do you see between:
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

Edited by Vllinator: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.