# how can i write a matlab code to a multple choice question having multiple answers?? say i have to pick out A,B,C,E but excluding D. so far i have this below...

10 views (last 30 days)
enoch adotey on 1 Jul 2015
Commented: enoch adotey on 2 Jul 2015
n=[A,B,C,E];
switch (n);
case 'D'; case 'd';
if n=='D'||n=='d'
fprintf('Your scored mark is zero(0)\n');
break;
end
if n=='A'||n=='a'&& n=='B'||n=='b'&& n=='C'||n=='c'&& n=='E'||n=='e';
break;
end
end
end
##### 2 CommentsShowHide 1 older comment
enoch adotey on 2 Jul 2015
thank you much for your correction, am looking through to make my changes

Nick on 1 Jul 2015
Edited: Nick on 1 Jul 2015
in = input('Get input: ','s');
switch lower(in)
case 'a'
disp('Right')
case 'b'
disp('Right')
case 'c'
disp('Right')
case 'd'
disp('Wrong')
case 'e'
disp('Right')
otherwise
disp('Invalid choice')
end
end
You can put a function in the correct cases instead of the disp('Right')answer ='a' so it runs the same function if you wanted to as well
##### 2 CommentsShowHide 1 older comment
enoch adotey on 2 Jul 2015
joseph am grateful you took your time to help me with the exact solution and it has given me a clearer understanding into programming. 2. i still need a clarification to simulate this: if assuming 1000 student took the exam with 30 questions, what will be the number of lucky_students that will have atleast 4 questions correct???

### Categories

Find more on Mathematics in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!