Divide if not zero Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


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:

Imports System
Public Class exercise17
    Public Shared Sub Main()
        Dim number1, number2 As Integer
        Console.Write("Enter the first number:")
        number1 = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter the second number:")
        number2 = Convert.ToInt32(Console.ReadLine())

        If number2 <> 0 Then
            Console.WriteLine("The result for {0} / {1} is {2}", number1, number2, number1 / number2)
        End If

        If number2 = 0 Then Console.WriteLine("No result")
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.