21 game

You are encouraged to solve this task according to the task description, using any language you may know.
21 is a two player game, the game is played by choosing
a number (1, 2, or 3) to be added to the running total.

The game is won by the player whose chosen number causes the running total
to reach exactly 21.

The running total starts at zero.
One player will be the computer.

Players alternate supplying a number to be added to the running total.



Task

Write a computer program that will:

 do the prompting (or provide a button menu), 
 check for errors and display appropriate error messages, 
 do the additions (add a chosen number to the running total), 
 display the running total, 
 provide a mechanism for the player to quit/exit/halt/stop/close the program,
 issue a notification when there is a winner, and
 determine who goes first (maybe a random or user choice, or can be specified when the game begins). 


 
' Gambas module file
 
Private gameConunt As Integer = 0
Private numRound As Integer = 1
Private winPlayer As Integer = 0
Private winComputer As Integer = 0
 
 
Public Sub Main()
 
  Dim entra As String
 
  Print "Enter q to quit at any time\nThe computer will choose first"
 
  While gameConunt < 21
    Print "ROUND: " & numRound & "\n"
    gameConunt += selectCount(gameConunt)
    Print Subst("Running total is now &1 \n ", gameConunt)
    If gameConunt = 21 Then
      Inc winComputer
      Print "The computer has won !\n"
      endGame()
    Endif
    gameConunt += humanCount(gameConunt)
    Print Subst("Running total is now &1", gameConunt)
    If gameConunt = 21 Then
      Inc winPlayer
      Print "Congratulations! You've won!\n"
      endGame()
    Endif
    Inc numRound
  Wend
 
End
 
Private Function selectCount(cou As Integer) As Integer
 
  Dim a As Integer
 
  Randomize
 
  If cou < 18 Then
    a = Int(Rnd(1, 4))
  Else
    a = 21 - cou
  Endif
 
  Print "The computer choose " & a
 
  Return a
 
End
 
Private Function humanCount(cou As Integer) As Integer
 
  Dim entra As String
  Dim a As Integer
 
  While True
    Print "Your choice 1 to 3"
    Input entra
    If entra = "q" Then
      Print "Good Bye!"
      Quit
    Endif
    Try a = CInt(entra)
    If Error Then
      Print "Invalid entry, try again"
      Continue
    Endif
    If a < 1 Or a > 3 Then
      Print "Out of range, try again"
      Continue
    Endif
    If a + cou > 21 Then
      Print "The sum is greater than 21, try again"
      Continue
    Endif    
    Return a
  Wend
 
End
 
 
Private Sub endGame()
 
  Dim entra As String
 
  Print Subst("Computer wins &1 games, human wins &2 games", winComputer, winPlayer)
  Print "\nPlay again? (y/n)"
  Input entra
  If entra = "y" Or entra = "Y" Then
    numRound = 1
    gameConunt = 0
    Print "Enter q to quit at any time\nThe computer will choose first"
  Else
    Print "Good Bye!"
    Quit
  Endif
 
End