title: Clear input buffer: Visual Basic
body: <p>I've just started with VB in VS2010 and attempting to write a simple console calculator. However, i can't get it to wait to display the output. The console window closes immediately even after putting a Console.Read(). I guess the input buffer from my ReadLine() still has some valid characters. I'll paste the code here:</p>
  
  <p>Sub Main()</p>
  
  <pre><code>    Dim num1 As Double
      Dim num2 As Double
      Dim op As Char
      Dim ans As Double
  
      Console.Write("Enter first number:")
  
      num1 = CType(Console.ReadLine(), Double)
  
      Console.Write("Enter second number:")
      num2 = CType(Console.ReadLine(), Double)
  
      Console.Write("Enter an operator:")
      op = ChrW(Console.Read())
  
      Select Case op
          Case "+"
              ans = num1 + num2
              Console.WriteLine("Result=" + ans.ToString())
  
          Case "-"
              ans = num1 - num2
              Console.WriteLine("Result=" + ans.ToString())
  
  
          Case "*"
              ans = num1 * num2
              Console.WriteLine("Result=" + ans.ToString())
  
          Case "/"
              If num2 &lt;&gt; 0 Then
                  ans = num1 / num2
                  Console.WriteLine("Result=" + ans.ToString())
              Else : Console.WriteLine("Error: Division by zero")
              End If
  
      End Select
  
      Console.Read()
  
  End Sub
  </code></pre>
  
  <p>I've noticed that i need to put 3 Console.Read()'s at the end of the code to finally get the console to wait. Why is this happening?</p>