Posted by: Sourav | December 21, 2012

A better calculator in visual basic using elseif


Dim a As Integer = Nothing
Dim b As Integer = Nothing
Dim c As String = Nothing
Dim d As Double = Nothing

 

Console.WriteLine(“Please enter the first number:”)
a = Console.ReadLine
Console.WriteLine(“Please enter the second number:”)
b = Console.ReadLine
Console.WriteLine(“Please enter the operation you want to perform:”)

c = Console.ReadLine
If c = “+” Then
d = a + b
ElseIf c = “-” Then
d = a – b
ElseIf c = “*” Then
d = a * b
ElseIf c = “/” Then
d = a / b
ElseIf c = “MOD” Then
d = a Mod b

Else
Console.WriteLine(“The valid operations are +,-,*,/and MOD,please use one of these”)

End If
If d = Nothing Then
Console.WriteLine(“Please run the program again and chosse a valid operation!!!”)

Else
Console.WriteLine(“The answer is ” & d)

End If

 

Console.ReadLine()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: