Write a MATLAB program that asks the user for an age and then classifies the age
ID: 2320647 • Letter: W
Question
Write a MATLAB program that asks the user for an age and then classifies the age according to the following scheme: If the user attempts to input an age less than zero or greater than 120 the program should display "error". If the user inputs an age less than 1, the program should display "baby", an age less than 13, the program should display "child", an age less than 20, the program should display "teenager", an age less than 60, the program should display "adult" and an age greater than 60 the program should display "senior".Explanation / Answer
You can change input according to you. Matlab code shown below
clc
clear all
close all
input=45;
if(input <=0 || input >=120)
error('Error input entered')
else
if (input > 0 && input < 1)
S=sprintf('Baby %s');
disp(S)
end
if (input > 1 && input < 13)
S=sprintf('Child %s');
disp(S)
end
if (input > 13 && input < 20)
S=sprintf('Teenager %s');
disp(S)
end
if (input > 20 && input < 60)
S=sprintf('Adult %s');
disp(S)
end
if (input > 60)
S=sprintf('Senior %s');
disp(S)
end
end
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.