Why do I keep getting a parse error?
2 views (last 30 days)
Show older comments
Hi Matlabers!
I am trying to make code to run the blackjack card game on Matlab as a class project and keep running into a parse error. I want to label the cards such as AS for "ace of spades", 2S for "two of spades", and so forth for the rest of the cards... In the code, I write the following:
AS=1 2S=2 3S=3
I continue the code for the rest of the cards but omit that here for the sake of brevity. When I try to run the code, AS=1 has no problem but 2S=2 and 3S=3 have a parse error that reads as:
Error: File: Project.m Line: 8 Column: 2 Unexpected MATLAB expression.
I see that I can get around this by renaming the variables as spade2=2 and spade3=3, etc. but this doesn't look as nice to me and would rather keep it as I was originally trying to do. OR even better, I would love it if I can replace the S in 2S or 3S with a picture of an actual spade. The same goes for a diamond, club, and heart for the rest of the cards. I'm hoping there is someone here that knows what to do!
P.S. I would also like AS "ace of spades" to take on the value of either 1 or 11 given the choice of the user. I know that I can write something such as:
AS = input( 'Enter value for Ace: ');
but doing this would allow the user to input any number they want. I would like to give them the input option, but only allow either a value of 1 or 11.
Thank's Matlabers!
2 Comments
Answers (1)
Walter Roberson
on 10 Apr 2018
There is no possibility of naming a variable beginning with a number. You must have a letter as the first character. Only letters and digits and underscore are permitted.
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!