Help! simple if and else statement password!
Oct 28, 2013 at 12:01pm UTC
I'm trying to make a simple password using if and else statement. My problem is It keeps saying "Access Allowed" even though I put a wrong number. help please.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <iostream>
using namespace std;
int main()
{
int pass;
cout << "Please type in the password." << endl;
cin >> pass;
if (pass == 45 || 65)
{
cout << "Access Allowed!" << endl;
}
else
{
cout << "Access Denied" ;
}
}
Oct 28, 2013 at 12:06pm UTC
Operator precedence. op== is evaluated before op||.
1 2 3 4 5 6
pass == 45 || 65
// is same as
(pass == 45) || 65
// Try
(pass == 45) || (pass == 65)
Oct 28, 2013 at 12:22pm UTC
Wow! Thank you very much! I'm trying to figure it out for about 30 minutes.
Topic archived. No new replies allowed.