Exercise
Password
Objetive
Write a Visual Basic (VB.Net) program to prompt the user to enter their login and password (both must be integer numbers) and repeat the prompt as many times as necessary until the entered login is "12" and the password is "1234".
Code
' 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