Write a MATLAB script utilizing IF-ELSEIF-ELSE statements that asks the user to
ID: 3804028 • Letter: W
Question
Write a MATLAB script utilizing IF-ELSEIF-ELSE statements that asks the user to enter a grade between 0 and 100 (0 is the minimum grade and 100 is the maximum). After the user has entered their grade, the computer must then assign the appropriate letter grade based on the list of criteria provided in the table below and display a statement informing the user the letter grade that they have earned. The minimal criterion for each letter grade is as follows: If the user has earned a grade of B, the computer must display the message: You earned a grade of. Your letter grade is B. The location given by must display the number grade that the user entered earlier. Therefore, if the user entered a grade of 74, the message must show: You earned a grade of 74. Your letter grade is B. If the user entered a grade of 56, the message must show: You earned a grade of 74. Your letter grade is F.Explanation / Answer
Here is the code for you:
score = input('Please enter the score: ');
grade = floor(score / 10);
if grade == 10
grade = 'A';
elseif grade == 9
grade = 'A';
elseif grade == 8
grade = 'B';
elseif grade == 7
grade = 'C';
elseif grade == 6
grade = 'D';
elseif grade == 5
grade = 'F';
elseif grade == 4
grade = 'F';
elseif grade == 3
grade = 'F';
elseif grade == 2
grade = 'F';
elseif grade == 1
grade = 'F';
elseif grade == 0
grade = 'F';
end
fprintf('You earned a grade of %d. Your letter grade is %c ', score, grade);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.