Greatest of three numbers Learn programming Visual Basic (VB.net)



Lesson:

Flow Control


Exercise:

Greatest of three numbers


Objetive:

Write a Visual Basic (VB.net) program that prompts the user to enter three numbers and displays the greatest one.


Code:

Imports System
Public Class exercise19
    Public Shared Sub Main()
        Dim number1, number2, number3 As Integer
        Console.Write("Enter the number 1:")
        number1 = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter the number 2:")
        number2 = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter the number 3:")
        number3 = Convert.ToInt32(Console.ReadLine())

        If number1 > number2 AndAlso number1 > number3 Then
            Console.WriteLine("The number 1 is greatest")
        ElseIf number2 > number1 AndAlso number2 > number3 Then
            Console.WriteLine("The number 2 is greatest")
        ElseIf number3 > number1 AndAlso number3 > number2 Then
            Console.WriteLine("The number 3 is greatest")
        Else
            Console.WriteLine("Numbers equals")
        End If
    End Sub
End Class



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