MATLAB: 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…

multiple answers

n=[A,B,C,E];
for n=input('Enter your answers:');
switch (n);
case 'D'; case 'd';
if n=='D'||n=='d'
disp('wrong answer. Try again please');
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';
disp('correct answers,congratulations!');
break;
end
end
end

Best Answer

answer = 'n'
while(answer ~= 'd')
in = input('Get input: ','s');
switch lower(in)
case 'a'
disp('Right')
answer = 'a';
case 'b'
disp('Right')
answer = 'b';
case 'c'
disp('Right')
answer = 'c';
case 'd'
disp('Wrong')
answer = 'd';
case 'e'
disp('Right')
answer = 'e';
otherwise
disp('Invalid choice')
answer = 'na';
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
Related Question