Ejercicio
Dividir si no es cero
Objetivo
Escriba un programa en Visual Basic para pedir al usuario dos números y muestre su división si el segundo número no es cero; de lo contrario, mostrará "No puedo dividir"
Código
' 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