Many divisions Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Many divisions 59


Objetive:

Write a Visual Basic (VB.net) program to ask the user for two numbers and show their division and the remainder of the division. It will warn if 0 is entered as second number, and end if 0 is entered as first number:

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