% This M-File calculates the width of the base of the tree
% Written by Michael Haggerty

poleHeight = -1;
stringLength = -1;

% An example of using a while loop to check input
while poleHeight <= 0
   poleHeight = input('Enter the pole height (must be greater than zero): ');
end

% Get the string Length
while stringLength < poleHeight
   stringLength = input('Enter a string length: ');
   % Validate input terminate if not valid - 
   % OK I'm not sure why someone would write the code
   % like this but understand the principle of breaking
   if stringLength < poleHeight
      disp('String length must be longer than pole height');
      disp('Terminating Program');
      break
   end
   % Calculate tree Base
   treeWidth = 2 * sqrt(stringLength.^2 - poleHeight.^2);
   string = ['The width of the base of tree is ' num2str(treeWidth)];
   disp(string);
end
