function branch_demos()
%---------------------------------------------------------------
%       USAGE: branch_demos()
%
%      AUTHOR: Col David S. Gibson       DATE: 17 Jan 05
%    MODIFIED: Dr. Wayne Brown           DATE:  7 Jul 05
%    MODIFIED: Maj William Wells           DATE:  22 Aug 07
%
% DESCRIPTION: Examples of MATLAB's selection statements.
%
%      INPUTS: None
%
%     OUTPUTS: None
%
%  REFERENCES: None
%---------------------------------------------------------------

% get body temperature from the user

Body_temp = input('Enter patient''s body temperature: ');

% one-alternative if

% body temp over 98.6     - display fever
% body temp not over 98.6 - do nothing

if Body_temp > 98.6
    fprintf('The patient has a fever.\n')
end 

%---------------------------------------------------------------

% two-alternitive if (if-else)

% body temp over 98.6     - display fever
% body temp not over 98.6 - display no fever

if Body_temp > 98.6
    fprintf('The patient has a fever.\n')
else
    fprintf('The patient does not have a fever.\n')
end

%---------------------------------------------------------------

% multiple-alternitive if (if-elseif) with else block
 
% body temp at or over 102        - display high fever
% body temp over 98.6 & under 102 - display low grade fever
% body temp at or under 98.6      - display no fever

if Body_temp >= 102
    fprintf('The patient has a high fever.\n')
elseif Body_temp > 98.6
    fprintf('The patient has a low grade fever.\n')
else
    fprintf('The patient does not have a fever.\n')
end

% note dependence on mutually exclusive cases to simplify tests!

%---------------------------------------------------------------

% multiple-alternative if (if-elseif) with more elseif blocks

% body temp at or over 102            - display high fever
% body temp at or over 99 & under 102 - display low grade fever
% body temp at or over 96 & under 99  - display normal range
% body temp at or over 92 & under 96  - display low temperature
% body temp below 92                  - display hypothermic

if Body_temp >= 102
    fprintf('The patient has a high fever.\n')
elseif Body_temp >= 99
    fprintf('The patient has a low grade fever.\n')
elseif Body_temp >= 96
    fprintf('The patient''temperature is in the normal range.\n')
elseif Body_temp >= 92
    fprintf('The patient has a low body temperature.\n');
else
    fprintf('The patient is hypothermic.\n');
end

% note again dependence on mutually exclusive cases
% Q: why not use switch for this?

%---------------------------------------------------------------

% multiple-alterntive if (if-elseif) without else block

% body temp at or over 102        - display high fever
% body temp over 98.6 & under 102 - display low grade fever
% body temp under 95              - display low temperature

if Body_temp >= 102
    fprintf('The patient has a high fever.\n')
elseif Body_temp > 98.6
    fprintf('The patient has a low grade fever.\n')
elseif Body_temp < 95
    fprintf('The patient has a low body temperature.\n')
end

% note no "else" clause when not all cases need an action

%---------------------------------------------------------------

% nested if statement

if Body_temp >= 102
    fprintf('The patient has a high fever.\n')
    WBC_count = input('Enter patient''s WBC count');
    if WBC_count > 10000
        fprintf('Recommend antibiotics\n')
    else
        fprintf('Recommend acetaminophen\n')
    end
elseif Body_temp > 98.6
    fprintf('Patient has a low grade fever.\n')
end

% note high fever and low WBC count are not mutually exclusive

%---------------------------------------------------------------

% switch with otherwise (integer switch expression)

Grad_year = input('Enter your graduation year: ');

switch (Grad_year)
    case 2011
        fprintf('You''re a doolie\n')
        fprintf('Focus on Personal leadership\n')
    case 2010
        fprintf('You''re a 3-degree\n')
        fprintf('Focus on Interpersonal leadership\n')        
    case 2009
        fprintf('You''re a 2-degree\n')
        fprintf('Focus on Team leadership\n')
    case 2008
        fprintf('You''re a firstie\n')
        fprintf('Focus on Organizational leadership\n')
    otherwise
        fprintf('You''re not a cadet\n')
end
    
%---------------------------------------------------------------

% switch with multiple option cases (char switch expression)

Answer = input('Do you like MATLAB? [y/n/?]: ', 's');

switch (Answer)
    case {'y', 'Y'}
        fprintf('I''m glad to hear you like MATLAB\n')
    case {'n', 'N'}
        fprintf('What''s not to like?\n')
    case '?'
        fprintf('Haven''t made up your mind yet have you?\n')
    otherwise
        fprintf('Non comprendo!\n')
end

%---------------------------------------------------------------

% try/catch construct

% set up 5-element vector and get an index

Vector = [2 4 6 8 10];
fprintf('\n\nVector = ')
disp(Vector)
Index = input('Enter an index for the vector: ');

% diplay the element at the entered index (if possible)

try
    % code prone to run time error (BAD CODE?!)
    fprintf('Vector(%g) = %G\n',Index, Vector(Index))
catch
    % error handler code
    fprintf('Sorry %g is not a valid index for matrix\n', Index)
end

%---------------------------------------------------------------

% end of branch_demos