VB.NET exercises and solutions: if else and comparison operators


VB.NET if else and comparison operators

Exercise 1: Write VB.NET program to allow the user to input his/her age.

Then the program will show if the person is eligible to vote. A person who is eligible to vote must be older than or equal to 18 years old.

Enter your age: 18

You are eligible to vote.

Solution:


Module Module1

Sub Main()
Dim age As Integer
Console.Write("Enter your age:")
age = Integer.Parse(Console.ReadLine())
If (age >= 18) Then
Console.WriteLine("You are eligible to vote.")
Else
Console.WriteLine("You are not eligible to vote.")
End If


Console.ReadLine()

End Sub

End Module

Exercise 2: Write a VB.NET program to determine whether an input number is an even number.


Module Module1

Sub Main()


Dim i As Integer
Console.Write("Enter a number:")
i = Integer.Parse(Console.ReadLine())
If (i Mod 2 = 0) Then
Console.WriteLine("It is an even number.")
Else
Console.WriteLine("It is an odd number.")
End If


Console.ReadLine()

End Sub

End Module




Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.