Ejercicio
Contraseña V2
Objetivo
Escriba un programa en Visual Basic para solicitar al usuario su nombre de usuario y su contraseña (ambos deben ser números enteros), hasta que el inicio de sesión ingresado sea "12" y la contraseña sea "1234". El usuario tendrá un máximo de 3 intentos.
Código
' 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