3.04 - Password, 5 attempts

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

Solution
using System;

public class Exercise051
{
    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!");
    }
}

Popular Posts