There is a calculator code that must add / subtract / multiply / divide two numbers.

Module Module1 Sub Main() Console.WriteLine("Enter the first digit... ") Dim x As Integer = Console.ReadLine() Console.WriteLine("Enter the second digit... ") Dim y As Integer = Console.ReadLine() Console.WriteLine("Choose operation(+, -, /, *)") If Console.ReadLine() = "*" Then Console.WriteLine(x * y) Console.ReadLine() ElseIf Console.ReadLine() = "/" Then Console.WriteLine(x / y) Console.ReadLine() ElseIf Console.ReadLine() = "+" Then Console.WriteLine(x + y) Console.ReadLine() ElseIf Console.ReadLine() = "-" Then Console.WriteLine(x - y) Console.ReadLine() End If End Sub End Module 

But it happens: But it happens After entering the sign of the operation with numbers and three clicks of Enter, the command line disappears. Perhaps I did not correctly assign values ​​to variables or did not output the result in the same way.

  • Well, what did you want? They themselves wrote such code ¯ \ _ (ツ) _ / ¯. For everything to work, * must be entered 1 time; / - 2 times, + - 3 times, - - 4 times - Kir_Antipov
  • @Kir_Antipov, and it really works. Do not tell me how to restrict one character? - Irvin
  • comrade, well, don't you understand that in your if-else chain in each condition you initiate a new input from the user. Read the line once, sticking the value into a variable, and then check the value of the variable) - Kir_Antipov
  • And here is an association about calculators - I recently answered - Kir_Antipov
  • @Irvin, to request an operation, make one ReadLine before the if block, write the result into a variable, and then check the value of the variable inside if . - insolor

0