Many divisions Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Many divisions


Objetive:

Write a Visual Basic (VB.net) program that asks the user for two numbers and displays their division and remainder of the division. If 0 is entered as the second number, it will warn the user and end the program if 0 is entered as the first number. Examples:

First number? 10
Second number? 2
Division is 5
Remainder is 0

First number? 10
Second number? 0
Cannot divide by 0

First number? 10
Second number? 3
Division is 3
Remainder is 1

First number? 0
Bye!


Code:

Imports System
Public Class Exercise32
    Public Shared Sub Main()
        Dim num1, num2 As Integer

        Do
            Console.Write("First number? ")
            num1 = Convert.ToInt32(Console.ReadLine())

            If num1 <> 0 Then
                Console.Write("Second number? ")
                num2 = Convert.ToInt32(Console.ReadLine())

                If num2 = 0 Then
                    Console.WriteLine("Cannot divide by 0")
                    Console.WriteLine()
                Else
                    Console.WriteLine("Division is {0}", num1 / num2)
                    Console.WriteLine("Remainder is {0}", num1 Mod num2)
                    Console.WriteLine()
                End If
            End If
        Loop While num1 <> 0

        Console.WriteLine("Bye!")
    End Sub
End Class