Ejercicio
Multiplicar si no es cero
Objetivo
Escriba un programa en Visual Basic para pedir al usuario un número; si no es cero, entonces pedirá un segundo número y mostrará su valor; de lo contrario, mostrará "0".
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 a number: ")
' Read the user's input and convert it to a double
Dim firstNumber As Double = Convert.ToDouble(Console.ReadLine())
' Check if the number is not zero
If firstNumber <> 0 Then
' Ask the user to input the second number
Console.Write("Enter another number: ")
' Read the second number
Dim secondNumber As Double = Convert.ToDouble(Console.ReadLine())
' Display the result of multiplying the two numbers
Console.WriteLine("The result is: " & (firstNumber * secondNumber))
Else
' If the first number is zero, display 0
Console.WriteLine("0")
End If
End Sub
End Class