Home - kric/21 GitHub Wiki

  1. clc

  2. clear

  3. y = 99;

  4. n = 98;

  5. cardmax =0;

  6. disp('your goal is to get to or as close as you can to 21')

  7. while cardmax <21

  8. carddraw = input ('Do you want to draw a card? (y/n): ');
    
  9. if carddraw == 99
    
  10.     Card = randi (10,1,1);
    
  11.     disp (Card)
    
  12.     cardmax = Card + cardmax;
    
  13. elseif carddraw == 98
    
  14.      str = sprintf ('you have ended with a score of: ');
    
  15. disp(str);
    
  16. disp(cardmax);
    
  17. cardmax = 99;
    
  18. end
    
  19. end

  20. if cardmax> 21

  21. disp ('You have lost')
    
  22. end

  23. if cardmax == 21

  24. disp('you have won')
    
  25. end