That is a little homework for myself. I was trying to make a simple program that you entry your name (acts as a password) and if it's on the list then you may access, otherwise (aka else) you're not allowed to access. The problem is I can't put more than two variables for one declaration (eg name == "James" || "Ellen" || "John") which || means OR, correct?

I can do the alternative: if (name = "James") {blah blah} else if (name = "Ellen") {blah blah, same as before one}, etc but that's long. I think OR operator would be easier but it doesn't work. Any suggestions?

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

int main() {
    string name;
    cout << "Password: ";
    cin >> name;
    if (name == "James" || "Ellen" || "John")
    { cout << "\nCommander!\n"; }
    else
    { cout << "\nDENIED!\n"; }
    system("pause");
    return 0;
}

Thanks but that didn't work. I figured it out. Here is the correct code for learners in the future :)

((name == "James") || (name == "Ellen") || (name == "John"))

Thanks but that didn't work

That's probably your compiler specific req. in using parentheses for that condition, even without those extra parentheses the program compiled/runned fine in my linux gcc

This question has already been answered. Start a new discussion instead.