Exercise
Average
Objetive
Write a Visual Basic (VB.Net) program to calculate and display the average of four numbers entered by the user.
Code
' Import the System namespace to use Console classImports System
Public Class Program
' Main subroutine, entry point of the program
Public Shared Sub Main()
' Prompt the user to enter the first number
Console.Write("Enter the first number: ")
' Read the user's input and convert it to a double
Dim num1 As Double = Convert.ToDouble(Console.ReadLine())
' Prompt the user to enter the second number
Console.Write("Enter the second number: ")
' Read the user's input and convert it to a double
Dim num2 As Double = Convert.ToDouble(Console.ReadLine())
' Prompt the user to enter the third number
Console.Write("Enter the third number: ")
' Read the user's input and convert it to a double
Dim num3 As Double = Convert.ToDouble(Console.ReadLine())
' Prompt the user to enter the fourth number
Console.Write("Enter the fourth number: ")
' Read the user's input and convert it to a double
Dim num4 As Double = Convert.ToDouble(Console.ReadLine())
' Calculate the average of the four numbers
Dim average As Double = (num1 + num2 + num3 + num4) / 4
' Display the calculated average
Console.WriteLine("The average is: " & average)
End Sub
End Class