Exercise
Multiply if not zero
Objetive
Write a Visual Basic (VB.Net) program to ask the user for a number; if it is not zero, then it will ask for a second number and display their sum; otherwise, it will display "0"
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 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