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

name == "James" || "Ellen" || "John") which || means OR, correct?

name == "James" || name == "Ellen" || name == "John"

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

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.