% -----------------------------------------------------
% classpercent_to_letter_grade.m
% -----------------------------------------------------
% Write a program that computes the letter grade for each student in 
% a class, when the grades are given as percentages. 
% -----------------------------------------------------
% Notes: Use a for loop. 
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------

% Clear all variables and clear the command window
clear
clc

% Define the grades of all students in a vector
grades = [100 90 50 100 64 72 99 30 0 95 85 30 45 80 70 85 70 70];

% Number of students
N = length(grades);

% For loop evaluates the letter grades of each student starting
% from the 1st, 2nd,...to the Nth grade. 

for k = 1:1:N
    % Conditional statements used to evaluate the letter grade based on 
    % given grading policy
    if grades(k) >= 90
        letter_grade(k) = 'A';
    elseif grades(k) >= 80
        letter_grade(k) = 'B';
    elseif grades(k) >= 70
        letter_grade(k) = 'C';
    elseif grades(k) >= 60
        letter_grade(k) = 'D';
    else
        letter_grade(k) = 'F';
    end
end

% Display both the percent grade and letter grade for each grade
disp('% grade');
disp(grades);
disp('letter grade');
disp(letter_grade);
