How to make matrix dimensions agree
Show older comments
I am trying to make a blackjack game and have gotten to where it is almost user-friendly.
%BlackJack single player game
clear; clc;
deck = [11 11 11 11 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10]; %assume all aces are worth 11
dealercount = 0;
playercount = 0;
playercard1 = deck(randperm(length(deck),1));
playercard2 = deck(randperm(length(deck),1));
playercard3 = deck(randperm(length(deck),1));
playercard4 = deck(randperm(length(deck),1));
dealercard1 = deck(randperm(length(deck),1));
dealercard2 = deck(randperm(length(deck),1));
dealercard3 = deck(randperm(length(deck),1));
dealercard4 = deck(randperm(length(deck),1));
if dealercount < 21
dealercount = dealercard1;
end
fprintf('What would you like to do? Hit or Stand?')
playerchoice = input('','s')
if playerchoice == 'Hit'
playercount = playercard1
else playerchoice == 'Stand'
playercount = playercount
end
When the player inputs Hit it works, but when they input Stand it says:
Matrix dimensions must agree.
Error in BlackJack (line 22)
if playerchoice == 'Hit'
How do I fix this?
Accepted Answer
More Answers (0)
Categories
Find more on Pulsed Waveforms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!