Password 5 attempts Learn programming C# Sharp

Lesson:

Basic Data Types


Exercise:

Password 5 attempts 16


Objetive:

Write a C# program which asks the user for his login and password. Both must be strings. After 5 wrong attempts, the user will be rejected.


Code:

using System;
public class Exercise52
{
    public static void Main()
    {
        string user, pass;
        int count = 0;

        do
        {
            Console.Write("Enter username: ");
            user = Console.ReadLine();

            Console.Write("Enter password: ");
            pass = Console.ReadLine();

            count++;

        }
        while (((user != "user") || (pass != "password"))
            && (count != 5));

        if (count == 5)
            Console.Write("Login attemp fail!");
        else
            Console.Write("Password correct!");
    }
}