Why do I keep getting a parse error?

2 visualizzazioni (ultimi 30 giorni)
Carlos Hernandez
Carlos Hernandez il 10 Apr 2018
Commentato: Carlos Hernandez il 14 Apr 2018
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 Commenti
KSSV
KSSV il 10 Apr 2018
2S=2 3S=3
The above is not allowed......you may use
S2=2 ; S3=3 ; instead

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 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.

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by