Drivers License Exam The local Drivers License Office has as
Solution
% This program is to conduct License Exam
correct_ans = [\'B\',\'D\',\'A\',\'A\',\'C\',\'A\',\'B\',\'A\',\'C\',\'D\',\'B\',\'C\',\'D\',\'A\',\'D\',\'C\',\'C\',\'B\',\'D\',\'A\']; % Correct answers
user_ans = [];
i = 0;
question_num = 20;
wrong_ans = [];
marks = 0;
while (i<question_num) % Reading input from user
option = input(\"Enter your answer ::\\t\",\"s\");
if (length(option) == 1 & (option == \'A\' | option == \'B\' | option ==\'C\' | option == \'D\')) % Validating the answer
user_ans = [user_ans,option];
i = i+1;
else
fprintf(\"This option is not Valid..!!! Please Try again \ \");
end
end
for ind = 1 : question_num % Validating the answers
if (correct_ans(ind) == user_ans(ind))
marks = marks + 1;
else
wrong_ans = [wrong_ans ind];
end
end
if (marks > 15)
disp(\"Congratulations....!! You passed the test.\");
else
disp(\"Sorry..!! U are failed the test\");
end
fprintf(\'\ The total number of correctly answered is : %d\', marks);
fprintf(\'\ The total number of uncorrectly answered is :: %d\', question_num - marks);
disp(\"\ Incorrectly answered question numbers :: \");
if (length(wrong_ans) == 0) % If all answers are right
disp(\" No question is found..!!\")
else
for ind = 1 : length(wrong_ans)
fprintf(\'\\t\\t %d \ \',ind);
end
end
