% Problem1 % Inititalize variables: clear; MAX = 10; % 10 marbles to start with MIN = 0; % can't have neg marables whiteTotal = randInt(MIN,MAX); % choose white marbles blackTotal = MAX - whiteTotal; % choose black marbles count = 0; % taken-marble counts % Extract marbles until one color runs out % or both colors run out: while whiteTotal >= MIN & blackTotal >= MIN & count < MAX % Take a marble: switch readInt(0,1,'Try to take a marble [0 (W),1 (B)]: ') case 0 if whiteTotal > MIN whiteTotal=whiteTotal-1; count = count+1; else disp('Sorry! Out of white marbles!'); end case 1 if blackTotal > 0 blackTotal=blackTotal-1; count = count+1; else disp('Sorry! Out of black marbles!'); end otherwise error('Error!'); end end % Report total amount of marbles taken. disp(['Total marbles taken: ',num2str(count)]);