Jump to content

C# HELP


Kakusas

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...