Kakusas Posted January 12, 2017 Posted January 12, 2017 Hi, i'm currently learning C# basics and I got and error in my code:        Console.WriteLine("Enter passwordi");       Console.Write("");       string psw = Console.ReadLine();       if (psw == "1234")         Console.WriteLine("Password is valid");       Console.ReadLine();     }       else {     Console.WriteLine(" Your password is not valid ");       Console.ReadLine();     }   } }   The part when I type 1234 as a password works, but if I try to write anything else, nothing happens. Â
Chronos Posted January 12, 2017 Posted January 12, 2017 It seems to work for me, although I had to fix a few things in regards to some scopes. (your if never opens a scope, and you seem to have copied a few extra from your project.) Â Console.WriteLine("Enter passwordi"); Console.Write(""); string psw = Console.ReadLine(); if (psw == "1234") { Â Â Â Console.WriteLine("Password is valid"); Â Â Â Console.ReadLine(); } else { Â Â Â Console.WriteLine(" Your password is not valid "); Â Â Â Console.ReadLine(); } Â It won't ever go back to asking you for a password once it fails though. Mcadams 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now