Write a MATLAB program that asks the user for an age and the
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\".
Solution
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
