function [win] = jurassicPark(me,bro)
wf='%s beats %s! Let''s go see the Utahraptors!';
lf='%s loses to %s. I guess the Utahraptors will have to wait.';
if strcmp(me,bro)
win='It''s a tie!';
elseif ~strcmp(me,bro)
switch me
case 'T-rex'
if strcmp(bro,'Velociraptor')||strcmp(bro,'Brachiosaurus')
win=sprintf(wf,me,bro);
else
win=sprintf(lf,me,bro);
end
case 'Velociraptor'
if strcmp(bro,'Pterodactyl')||strcmp(bro,'Stegosaurus')
win=sprintf(wf,me,bro);
else
win=sprintf(lf,me,bro);
end
case 'Stegosaurus'
if strcmp(bro,'T-rex')||strcmp(bro,'Pterodactyl')
win=sprintf(wf,me,bro);
else
win=sprintf(lf,me,bro);
end
case 'Pterodactyl'
if strcmp(bro,'Brachiosaurus')||strcmp(bro,'T-rex')
win=sprintf(wf,me,bro);
else
win=sprintf(lf,me,bro);
end
case 'Brachiosaurus'
if strcmp(bro,'Velociraptor')||strcmp(bro,'Stegosaurus')
win=sprintf(wf,me,bro);
else
win=sprintf(lf,me,bro);
end
end
end
end
You should not use strcmp in case after switch. Please read the documentation of switch.
Best Answer