Suppose that a student has the option of enrolling for a sin
Suppose that a student has the option of enrolling for a single elective during a term. The student must select a course from a limited list of options: \"English, \" \"History, \" \"Biology, \" \"Computer, \" or \"Math.\" Construct a fragment of MATLAB code that will prompt the student for his or her choice, read in the choice, and use the answer as the ease expression for a switch construct. Be sure to include a default case to handle invalid inputs. Testing three cases: (a) Computer (b) Physics (c) Biology.
Solution
disp(\'The following subjects are available:\');
disp(\'1. English\');
disp(\'2. History\');
disp(\'3. Biology\');
disp(\'4. Computer\');
disp(\'5. Math\');
c = input(\'Please select one of the above courses:(e.g.: 1 for english)\');
switch(c)
case 1
disp(\'You selected English\');
case 2
disp(\'You selected History\');
case 3
disp(\'You selected Biology\');
case 4
disp(\'You selected Computer\');
case 5
disp(\'You selected Math\');
otherwise
disp(\'Invalid input\');
end
