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). 


#define PLAYER 1
#define COMP   0
randomize timer
 
dim as uinteger sum, add = 0
dim as uinteger turn = int(rnd+0.5)
dim as uinteger precomp(0 to 3) = { 1, 1, 3, 2 } 
 
while sum < 21:
    turn = 1 - turn
    print using "The sum is ##"; sum
    if turn = PLAYER then
        print "It is your turn."
        while add < 1 orelse add > 3 orelse add+sum > 21
            input "How many would you like to add? ", add
        wend
    else
        print "It is the computer's turn."
        add = precomp(sum mod 4)
        print using "The computer adds #."; add
    end if
    print
    sum = sum + add
    add = 0
wend
 
if turn = PLAYER then
    print "Congratulations. You win."
else
    print "Bad luck. The computer wins."
end if