Exercise
Password V2
Objetive
Write a Visual Basic (VB.Net) program to ask the user for their login and password (both must be integer numbers) until the entered login is "12" and the password is "1234". The user will have a maximum of three attempts.
Code
' Importing necessary namespaces
Imports System
Public Class Program
Public Shared Sub Main()
' Declare variables for login, password, and attempt counter
Dim login As Integer
Dim password As Integer
Dim attempts As Integer = 0
' Loop to allow a maximum of 3 attempts
While attempts < 3
' Ask the user for the login
Console.WriteLine("Enter login:")
login = Convert.ToInt32(Console.ReadLine())
' Ask the user for the password
Console.WriteLine("Enter password:")
password = Convert.ToInt32(Console.ReadLine())
' Check if login and password are correct
If login = 12 AndAlso password = 1234 Then
Console.WriteLine("Access granted.")
Return ' Exit the program if the credentials are correct
Else
' Increment the number of attempts
attempts += 1
' Display a message if the login or password is incorrect
Console.WriteLine("Invalid login or password. Try again.")
End If
End While
' Inform the user if they failed to login after 3 attempts
Console.WriteLine("Maximum attempts reached. Access denied.")
End Sub
End Class