Ejercicio
Contraseña
Objetivo
Escribe un programa en Visual Basic para pedir al usuario su login y su contraseña (ambos deben ser números enteros) y repítelo tantas veces como sea necesario, hasta que el login introducido sea "12" y la contraseña sea "1234".
Código
' Import the System namespace for essential classes like Console and others
Imports System
' Define the class that contains the program
Public Class Program
' The Main method is the entry point of the program
Public Shared Sub Main()
' Declare variables for login and password to store the user inputs
Dim login As Integer
Dim password As Integer
' Use a do-while loop to repeatedly ask for login and password until they are correct
Do
' Prompt the user for their login
Console.Write("Enter your login: ")
login = Convert.ToInt32(Console.ReadLine()) ' Read the login input as an integer
' Prompt the user for their password
Console.Write("Enter your password: ")
password = Convert.ToInt32(Console.ReadLine()) ' Read the password input as an integer
' If the login or password are incorrect, display a message and continue the loop
If login <> 12 Or password <> 1234 Then
Console.WriteLine("Incorrect login or password. Please try again.")
End If
Loop While login <> 12 Or password <> 1234 ' Continue asking until the correct credentials are entered
' Once correct login and password are entered, display a success message
Console.WriteLine("Login successful!")
End Sub
End Class