% Factorial_Script.m - Greg Bucks - 10/8/2013
% Description: this script will compute the factorial for a number.  It
% will prompt the user for the value, check to ensure the value is valid,
% then compute the factorial.
% Usage: >> Factorial_Script;

% get value from user and ensure the value is valid
x = 0;
while x < 1 || mod(x,1) > 0         % check for negative and non-integer values
    x = input('Please enter your value: ');
    if x < 1
        fprintf('You must enter a non-negative value.\n');
    elseif mod(x,1) > 0
        fprintf('You must enter an integer value.\n');
    end
end

% compute the factorial
x_factorial = 1;
for k = x:-1:1
    x_factorial = x_factorial*k;
end

% display the results
fprintf('The factorial of %d is %d.\n',x,x_factorial);