% guessing_game.m
% Russ Poldrack, 12/30/02
% This program will ask the user for input, and will determine 
% whether it matches a magic (random) number

% first, determine the magic random number
% use rand(), which returns a random number between 0-1
% and ceil(), which rounds up a floating point number to the 
% nearest integer

magic_number_range = 5;  % the maximum allowable magic number

magic_number = ceil(rand * magic_number_range);

% now, ask the user to guess the magic number
% sprintf is like fprintf, but it returns a string rather than printing
% to the screen
% also note that you can use ... to continue a command across multiple lines

input_prompt=sprintf('Guess a number between 1 and %d\n',...
	magic_number_range);

guess = input(input_prompt);

% test the guess to see if it is correct, and provide feedback

if guess == magic_number,
	fprintf('GOOD GUESS!\n');
else,
	fprintf('sorry, the magic number is %d\n',magic_number);
end;

