Password VB.Net Exercise - Visual Basic Programming Course


 Lesson

Flow Control

 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

More VB.Net Exercises of Flow Control

 Positive and negative
Write a Visual Basic (VB.Net) program to get a number and answer whether it is positive or negative....
 Multiply if not zero
Write a Visual Basic (VB.Net) program to ask the user for a number; if it is not zero, then it will ask for a second number and display their sum; oth...
 Divide if not zero
Write a Visual Basic (VB.Net) program to ask the user for two numbers and display their division if the second number is not zero; otherwise, it will ...
 Divide if not zero (Using else)
Write a version of the previous program using 'else'. The program should ask the user for two numbers, and if the second number is not zero, it will d...
 Greatest of three numbers
Write a Visual Basic (VB.Net) program that prompts the user to enter three numbers and displays the greatest one....
 Repeat until 0
Write a Visual Basic (VB.Net) program to ask the user for a number "x" and display 10*x. It must repeat until the user enters 0 (using "while")....
 Repeat until 0 (Use Do While)
Write a Visual Basic (VB.Net) program that asks the user for a number "x" and displays 10*x. The program must repeat the process until the user enters...
 While + Counter
Write a Visual Basic (VB.Net) program to display the numbers 1 to 10 on the screen using "while"....
 Multiplication table (use while)
Write a Visual Basic (VB.Net) program that prompts the user to enter a number and displays its multiplication table using a 'while' loop....
 Odd numbers descending
Write a Visual Basic (VB.Net) program to display the odd numbers from 15 to 7 (downwards) on the screen using "while"....
 Sum numbers
Write a Visual Basic (VB.Net) program to ask the user for an undetermined amount of numbers (until 0 is entered) and display their sum, as follows: ...
 Two negative numbers
Write a Visual Basic (VB.Net) program to prompt the user for two numbers and determine if both numbers are negative or not....
 One or two negative numbers
Write a Visual Basic (VB.Net) program to prompt the user for two numbers and determine whether both are negative, only one is negative, or neither is ...
 Multiples
Write a Visual Basic (VB.Net) program to display on the screen the numbers from 1 to 500 that are multiples of both 3 and 5. (Hint: Use the modulo ope...
 Number repeated
Write a Visual Basic (VB.Net) program that asks the user for a number and a quantity, and displays that number repeated as many times as the user has ...
 Password V2
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 ...
 Many divisions
Write a Visual Basic (VB.Net) program that asks the user for two numbers and displays their division and remainder of the division. If 0 is entered as...
 Several multiplication tables, (use do while)
Write a Visual Basic (VB.Net) program that display multiplication tables from 2 to 6 using nested "do...while" loops....
 Square
Write a Visual Basic (VB.Net) program that prompts the user to enter a number and a width, and displays a square of that width, using that number for ...
 Break & continue
Write a Visual Basic (VB.Net) program to write the even numbers from 10 to 20, both inclusive, except 16, in 3 different ways: Incrementing 2 in ea...
 Rectangle V2
Write a Visual Basic (VB.Net) program that asks for a number, width, and height, and displays a rectangle of that width and height, using that number ...
 Repetitive structures
Write a Visual Basic (VB.Net) program that prompts the user for two numbers and displays the numbers between them (inclusive) three times using "for",...
 Digits in a number
Write a Visual Basic (VB.Net) program to calculate the number of digits in a positive integer (hint: this can be done by repeatedly dividing by 10). I...
 Hollow square
Write a Visual Basic (VB.Net) program that asks for a symbol and a width, and displays a hollow square of that width using that symbol for the outer b...
 Product
Write a Visual Basic (VB.Net) program that asks the user for two integer numbers and shows their multiplication, but not using "*". It should use cons...
 Absolute value
Write a Visual Basic (VB.Net) program to calculate (and display) the absolute value of a number x: if the number is positive, its absolute value is ex...
 Hollow rectangle
Write a Visual Basic (VB.Net) program that prompts for a symbol, a width, and a height, and displays a hollow rectangle of that width and height, usin...
 Statistics
Write a Visual Basic (VB.Net) program to calculate various basic statistical operations: it will accept numbers from the user and display their sum, a...
 Switch
Write a Visual Basic (VB.Net) program to display the text grade corresponding to a given numerical grade, using the following equivalence: 9,10 = E...
 Conditional operator, positive & smaller
Write a Visual Basic (VB.Net) program that asks the user for two numbers and answers, using the conditional operator (?), for the following: If the...
 Prime number
Write a Visual Basic (VB.Net) program that asks the user for an integer and determines if it is a prime number or not....
 Give change
Write a Visual Basic (VB.Net) program to give change for a purchase, using the largest possible coins (or bills). Suppose we have an unlimited amount ...
 Exceptions
Write a Visual Basic (VB.Net) program to prompt the user for two numbers and display their division. Errors should be caught using "try..catch"...


Juan A. Ripoll - Systems Tutorials and Programming Courses © 2024 All rights reserved.  Legal Conditions.