Matlab
% Guess what number for MATLAB 7.5.0
% rCX. 2009, public domain

MIN = 1;
MAX = 100;
Plr_Guess = -1;

while true()
    clc %Clear Command Window
    Randomed = uint8(rand() * ((MAX + 1) - MIN) + MIN);
    rounds = 0;
    disp(['Ok, i think random integer between ',num2str(MIN),' and ',num2str(MAX),'.'])
    disp('Your job is to guess what it is in as minimal tries as possible.')
    disp(' ')
    disp('After your every guess, ill give you hint is my number higher or lower than your guess.')
    disp('You can exit by ''guessing'' 0.')
    disp('Press any key to start game.')
    pause

    clc
    while true()
        rounds = rounds + 1;
        disp(['This is round number: ',num2str(rounds),'.'])

        Plr_Guess = str2num(input('Give your guess: ','s'));  %'s' tells MATLAB to return input as string

        if Plr_Guess == 0
            return  %exit program
        elseif Plr_Guess > Randomed
            disp('My number is smaller...')
        elseif Plr_Guess < Randomed
            disp('My number is higher...')
        elseif Plr_Guess == Randomed
            break
        else
            return %exit program
        end

        disp(' ')
    end

    disp('You got it!!!')
    disp(['It took ',num2str(rounds),' rounds to guess right number.'])
    disp(' ')
    key = input('Do you want to play again? Enter ''y'' or ''n''. ','s');

    if  ~strcmp(key,'y') && ~strcmp(key,'Y')
        break
    end
end
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.