Exercise
Divide if not zero
Objetive
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 display "I cannot divide".
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())
' Check if the second number is not zero
If secondNumber <> 0 Then
' Display the result of dividing the first number by the second
Console.WriteLine("The result is: " & (firstNumber / secondNumber))
Else
' If the second number is zero, display "I cannot divide"
Console.WriteLine("I cannot divide")
End If
End Sub
End Class