Exercise
One or two negative numbers
Objetive
Write a Visual Basic (VB.Net) program to prompt the user for two numbers and determine whether both are negative, only one is negative, or neither is negative.
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()
' Declare variables to store the two numbers entered by the user
Dim num1 As Integer
Dim num2 As Integer
' Prompt the user to enter the first number
Console.Write("Enter the first number: ")
num1 = Integer.Parse(Console.ReadLine())
' Prompt the user to enter the second number
Console.Write("Enter the second number: ")
num2 = Integer.Parse(Console.ReadLine())
' Check the conditions for both numbers being negative, one negative, or neither
If num1 < 0 AndAlso num2 < 0 Then
' If both numbers are negative, display this message
Console.WriteLine("Both numbers are negative.")
ElseIf num1 < 0 OrElse num2 < 0 Then
' If only one of the numbers is negative, display this message
Console.WriteLine("One number is negative.")
Else
' If neither of the numbers is negative, display this message
Console.WriteLine("Neither of the numbers is negative.")
End If
End Sub
End Class