% -----------------------------------------------------
% whileloop_writestatement.m
% -----------------------------------------------------
% Problem objective - to ask the user to work hard till he gets an A.  
% -----------------------------------------------------
% Notes: See algorithm shown below.  
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------

% Algorithm

% 1. Initialize the grade (first input)
% 2. Set the while conditions
% 3. If condition is true, display output 1
% 4. If condition is false, display output 2

clear;
clc;

% read in grade from user (Options: A, B, C, D, F) and ensure answer is valid
grade = input('Enter your current letter grade in ENGR 1731/1121 : ','s');

if grade == 'A' || grade == 'B' || grade == 'C' || grade == 'D' || grade == 'F'
    
    % encourage student until they get an A
    while grade == 'B' || grade == 'C' || grade == 'D' || grade == 'F'
        
        % display message if grade is not A
        disp('I will work hard in ENGR 1731/1121!');
        
        % enter updated grade (Options: A, B, C, D, F)
        grade = input('Enter your current letter grade in ENGR 1731/1121 : ','s');
        
    end
    
    % ensure user input is vaild, otherwise, display error message
    if grade == 'A'
        disp('Good job!');
    else
        fprintf('error, invalid grade entry, restart program\n');
    end
    
else
    fprintf('error, invalid grade entry, restart program\n');
end

% Quiz questions: 
% Is MATLAB case-sensitive? 
