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
' Import the System namespace to use Console class
Imports System
Public Class Program
' Main subroutine, entry point of the program
Public Shared Sub Main()
' Ask the user to input the first number
Console.Write("Enter the first number: ")
' Read the user's input and convert it to a double
Dim firstNumber As Double = Convert.ToDouble(Console.ReadLine())
' Ask the user to input the second number
Console.Write("Enter the second number: ")
' Read the second number and convert it to a double
Dim secondNumber As Double = Convert.ToDouble(Console.ReadLine())
' Ask the user to input the third number
Console.Write("Enter the third number: ")
' Read the third number and convert it to a double
Dim thirdNumber As Double = Convert.ToDouble(Console.ReadLine())
' Determine the greatest number using conditional statements
Dim greatest As Double = firstNumber
If secondNumber > greatest Then
greatest = secondNumber
End If
If thirdNumber > greatest Then
greatest = thirdNumber
End If
' Display the greatest number
Console.WriteLine("The greatest number is: " & greatest)
End Sub
End Class