Created
November 19, 2017 04:17
-
-
Save hpcslag/b4c61fa776a6e55ccdfdf4a604bfd71d to your computer and use it in GitHub Desktop.
Matlab homework 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function guessNumber(m,n) | |
%call guessNumber(m,n) to play the game | |
%example: | |
%guessNumber(1,10) to play the game in range 1 to 10 | |
% | |
r = randperm(n); | |
ans = r(m); | |
range_x = m; | |
range_y = n; | |
in = -1; | |
while (in) ~= ans | |
fprintf('Please Enter Number Between %i to %i\n',range_x,range_y) | |
in = input('Enter Number: '); | |
if in == ans | |
fprintf('You got it.\n') | |
ask = 0; | |
while (ask ~= 1)&&(ask ~=2) | |
ask = input('Do you want to play again? (1. YES, 2. NO): ') | |
end | |
if ( ask == 1) | |
guessNumber(m,n) | |
end | |
break; | |
else | |
fprintf('Wrong Answer, try again!\n') | |
if in < ans | |
range_x = in; | |
else | |
range_y = in; | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment