% -----------------------------------------------------
% percent_to_letter_grade.m
% -----------------------------------------------------
% Write a program that asks the user to input his/her current grade in the
% class as a percentage (between 0-100), uses this to evaluate his/her
% letter grade based on given grading policy and displays the output. 
% -----------------------------------------------------
% Notes: This problem is from the textbook
% Engineering Computation with MATLAB by David M. Smith. 
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------

clear;
clc;

% Ask user to input current grade as a percent (between 0-100). 
grade = input('Enter your current grade (%) in the class : ');

% evaluate the letter grade based on given grading policy
if grade > 100 || grade < 0 % || is logical 'or'
    letGrade = 'Numerical value is out of range';
elseif grade >= 90 && grade <= 100 
    letGrade = 'A';
elseif grade >= 80 && grade < 90 % && is logical 'and'
    letGrade = 'B';
elseif grade >= 70 && grade < 80
    letGrade = 'C';
elseif grade >= 60 && grade < 70
    letGrade = 'D';
% Note that else implies all other conditions were false.  
% There is no other condition associated with else.
else        
    letGrade = 'F';
end 

% Display output which is the letter grade
disp('Your letter grade is as shown below : ');
disp(letGrade);
