MATLAB: Using fprintf within a function

fprintf within function

The function goes like this. How do I enter an fprintf statement so that the output looks like this:
>>num2let(83)
>>The corresponding letter grade to 83 is:B
function [grade]= num2let(n)
If n>89.49
grade='A'
elseif n<=89.49 & n=>79.5
grade='B'
……
elseif n<59.5 grade='F'
end
end

Best Answer

hi Caleb,
You can define your function without output like this :
function []= num2let(n)
if n > 89.49
fprintf('>>The corresponding letter grade to %d is:A\n',n)
elseif n<=89.49 && n>=79.5
fprintf('>>The corresponding letter grade to %d is:B\n',n)
% YOU COMPLETE YOUR FUNCTION WITH OTHER TESTS
elseif n<59.5
% grade='F'
fprintf('>>The corresponding letter grade to %d is:F\n',n)
end
end