Password V2 Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Password V2 81


Objetive:

Write a Visual Basic (VB.net) program to ask the user for his/her login and his/her password (both must be integer numbers), until the entered login is "12" and the password is "1234". The user will have 3 attempts maximum.


Code:

Imports System
Public Class Exercise31
    Public Shared Sub Main()
        Dim user, pass As Integer
        Dim counter As Integer = 0

        Do
            Console.Write("Enter a user:  ")
            user = Convert.ToInt32(Console.ReadLine())
            Console.Write("Enter a password:  ")
            pass = Convert.ToInt32(Console.ReadLine())

            If (user <> 12) OrElse (pass <> 1234) Then
                Console.WriteLine("Login Error")
                counter += 1
            End If
        Loop While ((user <> 12) OrElse (pass <> 1234)) AndAlso (counter <> 3)

        If (user <> 12) OrElse (pass <> 1234) Then
            Console.WriteLine("Logged out!")
        Else
            Console.WriteLine("Login successful")
        End If
    End Sub
End Class