lundi 3 octobre 2016

Calculator -If statement error

I am trying to make a calculator on VisualBasics console application which will allow the user to add and subtract. I have figured out how to allow to digits inputted from the user to be added but I gave an option asking the user what operation they would like to use. However when the user uses the - sign it doesn't output the result of what the answer is to the two numbers inputted.

I used a elseif statement as I thought that when the line is read and that if "-" has been inputted then the program will not add the two numbers but now take them away. Could some one please explain to me why it doesn't allow me to choose the second option and take the two numbers away from one another?

Module Module1

    Sub Main()

        Console.WriteLine("Please enter the first number:")
        Dim num1 As Double = Console.ReadLine()
        Console.WriteLine("First number:" & num1)

        Console.WriteLine("Please enter the second number:")
        Dim num2 As Double = Console.ReadLine()
        Console.WriteLine("Second Number:" & num2)

        Console.Write("what operand do you want to use: +,-,:")
        If Console.ReadLine = "+" Then
            Console.WriteLine("The numbers added is:" & num1 + num2)
        ElseIf Console.ReadLine = "-" Then
            Console.WriteLine("The numbers subtracted is:" & num1 - num2)
        End If
        Console.ReadLine()

    End Sub

End Module

Aucun commentaire:

Enregistrer un commentaire