Author |
Topic: Syntax error??? (Read 589 times) |
|
coolguy
New Member
member is offline


Posts: 7
|
 |
Syntax error???
« Thread started on: Apr 4th, 2013, 1:05pm » |
|
Hello all,
I have used the following code but am not sure where I have gone wrong, the error keeps coming up with Syntax error. My aim is to allow the user to try the program again if they don't choose from the dice given.
Code:
INPUT "Choose which dice to throw, 4, 6 or 12." Choice% CASE Choice% OF WHEN 4 PRINT "4 sided dice thrown, score "; Dice1 WHEN 6 PRINT "6 sided dice thrown, score ";Dice2 WHEN 12 PRINT "12 sided dice thrown, score ";Dice3 WHEN <> 4 OR 6 OR 12 PRINT "ERROR" ENDCASE
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Syntax error???
« Reply #1 on: Apr 4th, 2013, 9:17pm » |
|
on Apr 4th, 2013, 1:05pm, coolguy wrote:I have used the following code but am not sure where I have gone wrong, the error keeps coming up with Syntax error. |
|
You need to replace the last of your cases with an OTHERWISE clause:
Code: INPUT "Choose which dice to throw, 4, 6 or 12." Choice%
CASE Choice% OF
WHEN 4 PRINT "4 sided dice thrown, score "; Dice1
WHEN 6 PRINT "6 sided dice thrown, score ";Dice2
WHEN 12 PRINT "12 sided dice thrown, score ";Dice3
OTHERWISE PRINT "ERROR"
ENDCASE Richard.
|
|
Logged
|
|
|
|
coolguy
New Member
member is offline


Posts: 7
|
 |
Re: Syntax error???
« Reply #2 on: Apr 5th, 2013, 10:13am » |
|
Hi Richard
I was unaware of any such syntax, thank you for clearing it up, works perfectly well now. Thanks a lot.
Regards
|
|
Logged
|
|
|
|
JGHarston
Junior Member
member is offline


Gender: 
Posts: 52
|
 |
Re: Syntax error???
« Reply #3 on: May 13th, 2013, 9:36pm » |
|
on Apr 4th, 2013, 1:05pm, coolguy wrote: CASE Choice% OF WHEN 4 PRINT "4 sided dice thrown, score "; Dice1 WHEN 6 PRINT "6 sided dice thrown, score " ice2 WHEN 12 PRINT "12 sided dice thrown, score " ice3 WHEN <> 4 OR 6 OR 12 PRINT "ERROR" ENDCASE |
| The parameters to WHEN are a constant expression, just like any other constant expression. What happens if you do: PRINT 4 PRINT 6 PRINT <> 4 OR 6 OR 12
Often the simplest way to start debugging a piece of code is to PRINT each of the parameters and see what happens.
on Apr 5th, 2013, 10:13am, coolguy wrote:I was unaware of any such syntax, thank you for clearing it up, works perfectly well now. Thanks a lot. |
| Help -> Help topics -> CASE
|
« Last Edit: May 13th, 2013, 9:36pm by JGHarston » |
Logged
|
|
|
|
|