Exercise
Function calculator, params of Main
Objetive
Write a Visual Basic (VB.Net) program to calculate a sum, subtraction, product or division, analyzing the command line parameters:
calc 5 + 379
(Parameters must be a number, a sign, and another number; allowed signs are + - * x / )
Code
Imports System
Public Class exercise125
Private Shared Sub Main()
Dim operation As Char = Convert.ToChar(args(1))
Dim number1 As Integer = Convert.ToInt32(args(0))
Dim number2 As Integer = Convert.ToInt32(args(2))
Dim result As Integer = 0
If args.Length <> 3 Then
Select Case operation
Case "+"c
result = number1 + number2
Case "-"c
result = number1 - number2
Case "x"c, "X"c, "*"c
result = number1 * number2
Case "/"c
result = number1 / number2
End Select
Console.WriteLine("Result: {0}", result)
Else
Console.WriteLine("Error in arguments")
End If
End Sub
End Class