If valid password is entered output is:- "Invalid password. Please enter again."
Please advise me the error in this program?
// Program asks user to enter password
// If password is not "home", "lady" or "mouse"
// the user must re-enter the password
using System;
public class DebugFive2
{
public static void Main()
{
const string pass1 = "home";
const string pass2 = "lady";
const string pass3 = "mouse";
string password;
Console.Write("Please enter your password ");
password = Console.ReadLine();
while (password != pass1 || password != pass2 || password != pass3)
{
Console.WriteLine("Invalid password. Please enter again. ");
password = Console.ReadLine();
}
Console.WriteLine("Valid password");
}
}
Loading
Sukesh MarlaPosted Aug 12, 2012, 1:25 AM
This is the right way of doing..
Hope It Helped. Please Mark answer as Accepted Answer.
Sukesh MarlaPosted Aug 12, 2012, 2:05 AM
Posted Aug 12, 2012, 2:04 AM
Sukesh MarlaPosted Aug 12, 2012, 2:00 AM
Please Check This is correct answer. bagzli :) if it helped
bagzliPosted Aug 12, 2012, 1:58 AM
bagzliPosted Aug 11, 2012, 9:22 PM
Example
while(pass1.Equals(password) || pass2.Equals(password) || pass3.Equals(password))
{
//bad pass enter again
}
//correct pass