Guess the number/With feedback (player): Difference between revisions
Content deleted Content added
Added MATLAB example |
m MATLAB: More input options |
||
Line 1,148: | Line 1,148: | ||
score = input(sprintf( ... |
score = input(sprintf( ... |
||
'Is %d too high (H), too low (L), or equal (E)? ', guess), 's'); |
'Is %d too high (H), too low (L), or equal (E)? ', guess), 's'); |
||
if any(strcmpi(score, {'h' 'hi' 'high' 'too high'})) |
if any(strcmpi(score, {'h' 'hi' 'high' 'too high' '+'})) |
||
highVal = guess-1; |
highVal = guess-1; |
||
nGuesses = nGuesses+1; |
nGuesses = nGuesses+1; |
||
elseif any(strcmpi(score, {'l' 'lo' 'low' 'too low'})) |
elseif any(strcmpi(score, {'l' 'lo' 'low' 'too low' '-'})) |
||
lowVal = guess+1; |
lowVal = guess+1; |
||
nGuesses = nGuesses+1; |
nGuesses = nGuesses+1; |
||
elseif any(strcmpi(score, {'e' 'eq' 'equal' 'right' 'correct'})) |
elseif any(strcmpi(score, {'e' 'eq' 'equal' 'right' 'correct' '='})) |
||
fprintf('Yay! I win in %d guesses.\n', nGuesses) |
fprintf('Yay! I win in %d guesses.\n', nGuesses) |
||
done = true; |
done = true; |