Implement a simple password that takes two

I have a question: How csn I build a password system that takes a password in the form of a number but it either of two numbers have to be valid, but I just can use one If Statement to do the check.

#include <iostream>

using namespace std;

int main()
{
int password;
cout << "Please enter your password:\n";
cin >> password;
cout << " " << "\n";

if ( password == 2020 && 0202 ) // Im trying to put "password" with two values, that when you enter 2020 or 0202 the if statement works but it doesnt work as I planed.
{
cout << " Access accepted\n";
}

else
{
cout << "Bye\n";
return main();
}
}
Replace the and operator (&&) withor operator (||)
Every "test" in an if statement has to be able to stand on its own.

The 0202 part of your if statement is not connected to your password == at all. The 0202 is evaluated by itself as True because anything non-zero value is true in C++.

Also, I believe you want the logical OR here instead of AND, since a password can't be the two different numbers at once.

tl;dr In other words, you have to make it
if ( password == 2020 || password == 0202 )
Last edited on
Topic archived. No new replies allowed.