RosettaCodeData/Task/21-game/Fortran/21-game-2.f
2023-07-01 13:44:08 -04:00

31 lines
731 B
Forth

#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