function varargout = addmult_soln(varargin)
% ADDMULT_SOLN Solution to variable input exercise.

if nargin < 2
  error('Too few input arguments.');
end

s = 0; p = 1;

% EXTRA CREDIT: Validate input sizes.

rows = []; cols = [];

for ix = 1:nargin
  [r,c] = size(varargin{ix});
  if r ~=1 || c ~= 1            % If not a scalar...
    if isempty(rows)   
      rows = r; cols = c;       % First time? Hold value.
    elseif r ~= rows || c ~= cols      % Check vs. old.
        error('Inputs do not match in size!');
    end
  end
end

% Ready to loop through values.

for ix = 1:nargin      % Loop through inputs
  val = varargin{ix};  % Extract using curly braces
  s = s + val;         % Sum increases by value
  p = p .* val;        % Product is multiplied
end

% Concatenate outputs if needed.

if nargout < 2         % nargout can be zero!
  warning('addmult_soln:twoOut',...
    'This function prefers two outputs.'); 
  varargout{1} = [s p];  % Concatenate outputs
else                   
  varargout{1} = s;
  varargout{2} = p;    % Separate if two outputs
end