Program crash and delete key doesn`t work.
Posted: Sat Apr 05, 2014 6:18 am
In the following program, two problems when a number is entered the delete(backspace) key doesn`t work to delete a number if you enter it wrong. Also if you don`t enter a number at all and hit enter it crashes because it is expecting an integer, I would like it to just let you reenter a number, any solutions for these two issues?
`THIS PROGRAM PLAYS BATNUM
DIM N as Integer
DIM K as integer
DIM X as integer
DIM Y as integer
DIM Q as integer
RANDOMIZE TIMER
120:
K = 20 + INT(10*RND)+10
N = 5 + INT(1000*RND)
PRINT " LEGAL MOVES ARE: "
PRINT " TAKE AWAY 1 THROUGH "
PRINT "? " :print K
PRINT " LAST PERSON TO MOVE LOSES."
PRINT
PRINT " THE INITIAL NUMBER IS "
PRINT "? ?? ": print N
210:
`OPPONENTS MOVE
PRINT "? ? YOUR MOVE ";
INPUT X
IF X > K THEN goto 270
IF X < 1 THEN goto 270
IF X <= N THEN goto 310
270:
PRINT " ILLEGAL MOVE."
PRINT
GOTO 210
310:
`TEST FOR WIN.
N = N - X
IF N > 0 THEN goto 410
PRINT " I WIN*** "
350:
cls
PRINT
PRINT
PRINT " NEW GAME. "
PRINT
GOTO 120
410:
` MACHINE`S MOVE
Q = INT ((N-1)/(K+1))
Y = N - 1 - Q*(K+1)
IF Y = 0 THEN goto 530
450:
N = N - Y
PRINT " MY MOVE IS "
PRINT Y
IF N = 0 THEN goto 600
PRINT " NEW TOTAL IS "
PRINT N
GOTO 210
530:
`MAKE RANDOM MOVE
IF N > 1 THEN goto 570
Y = 1
GOTO 450
570:
Y = 1 + INT(K*RND)
GOTO 450
600:
`MACHINE LOST.
PRINT " YOU WIN***"
GOTO 350
END
`THIS PROGRAM PLAYS BATNUM
DIM N as Integer
DIM K as integer
DIM X as integer
DIM Y as integer
DIM Q as integer
RANDOMIZE TIMER
120:
K = 20 + INT(10*RND)+10
N = 5 + INT(1000*RND)
PRINT " LEGAL MOVES ARE: "
PRINT " TAKE AWAY 1 THROUGH "
PRINT "? " :print K
PRINT " LAST PERSON TO MOVE LOSES."
PRINT " THE INITIAL NUMBER IS "
PRINT "? ?? ": print N
210:
`OPPONENTS MOVE
PRINT "? ? YOUR MOVE ";
INPUT X
IF X > K THEN goto 270
IF X < 1 THEN goto 270
IF X <= N THEN goto 310
270:
PRINT " ILLEGAL MOVE."
GOTO 210
310:
`TEST FOR WIN.
N = N - X
IF N > 0 THEN goto 410
PRINT " I WIN*** "
350:
cls
PRINT " NEW GAME. "
GOTO 120
410:
` MACHINE`S MOVE
Q = INT ((N-1)/(K+1))
Y = N - 1 - Q*(K+1)
IF Y = 0 THEN goto 530
450:
N = N - Y
PRINT " MY MOVE IS "
PRINT Y
IF N = 0 THEN goto 600
PRINT " NEW TOTAL IS "
PRINT N
GOTO 210
530:
`MAKE RANDOM MOVE
IF N > 1 THEN goto 570
Y = 1
GOTO 450
570:
Y = 1 + INT(K*RND)
GOTO 450
600:
`MACHINE LOST.
PRINT " YOU WIN***"
GOTO 350
END