You will write a program that prompts the user to enter a password.
Then evaluates whether the entered password is correct.
The correct password will be specified directly in the code.
You use if statement to verify the password.
C# if-else construction is shown here:
if (condition) { Statements to perform when the condition holds } else { Statements to perform otherwise }
using System; class Program//from ww w.jav a 2 s .co m { static void Main(string[] args) { // Input Console.Write("Enter password: "); string enteredPassword = Console.ReadLine(); // Password check if (enteredPassword == "friend") { Console.WriteLine("Password is OK, please enter"); } else { Console.WriteLine("Incorrect password"); } } }
If the compared values are the same, the test evaluates to true, the condition is considered fulfilled.
And the statements in the if branch are executed.
If the compared values are different, the test evaluates to false, the condition is considered not fulfilled.
And the statements in the else branch are executed.