Exercise
Several operations
Objetive
Write a Visual Basic (VB.Net) program to print on screen the result of adding, subtracting, multiplying and dividing two numbers typed by the user. The remainder of the division must be displayed, too.
It might look like this:
Enter a number: 12
Enter another number: 3
12 + 3 = 15
12 - 3 = 9
12 x 3 = 36
12 / 3 = 4 <
12 mod 3 = 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()
' Prompt the user to enter the first number
Console.Write("Enter the first number: ")
Dim number1 As Integer = Convert.ToInt32(Console.ReadLine())
' Prompt the user to enter the second number
Console.Write("Enter the second number: ")
Dim number2 As Integer = Convert.ToInt32(Console.ReadLine())
' Perform addition, subtraction, multiplication, division, and remainder
Dim sum As Integer = number1 + number2
Dim difference As Integer = number1 - number2
Dim product As Integer = number1 * number2
Dim quotient As Integer = number1 \ number2
Dim remainder As Integer = number1 Mod number2
' Display the results
Console.WriteLine("The result of adding the numbers is: " & sum)
Console.WriteLine("The result of subtracting the numbers is: " & difference)
Console.WriteLine("The result of multiplying the numbers is: " & product)
Console.WriteLine("The result of dividing the numbers is: " & quotient)
Console.WriteLine("The remainder of the division is: " & remainder)
End Sub
End Class