Tuesday, July 11, 2006

MATLAB 5.3: Two Age Programs

clc %For a SIMPLE solution
clear
age=input('Enter your age :')
if age > 65
disp('senior')
elseif age > 20
disp('adult')
elseif age > 13
disp('teen')
elseif age > 0
disp('child')
elseif age < style="color: rgb(204, 0, 0);">'unborn')
end



clc %For a RANGE solution
clear
age=input('Enter your age :')
if age < style="color: rgb(204, 0, 0);">'unborn')
elseif 0<=age & age <=12 disp('child')
elseif 13<=age & age <=19 disp('teen')
elseif 20<=age & age <=65 disp('adult')
else
disp('senior')
end

The homework solution was the second one but I came up with the first and it was accepted as the right answer.

No comments: