Code for PROGRAM TO EVALUATE A MULTIPLE-CHOICE TEST in C# Programming.
Write a program to check responses of a student to the multiple-choice exam in C#.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
static void Main(string[] args) { String correct_answers = "abbdd"; int question_count = correct_answers.Length; int correct_count = 0; char[] test_answers = new char[question_count]; char[] answer_sheet = correct_answers.ToCharArray(); Console.WriteLine("Answers can only be (a, b, c, d, null(n))"); Console.WriteLine(); int i = 0; while (i < question_count) { Console.Write("Input responses of student answer {0} :", i + 1); char ch = Convert.ToChar(Console.ReadLine()); if (ch == 'a' || ch == 'b' || ch == 'c' || ch == 'd' || ch == 'n') { test_answers[i] = ch; i++; } } Console.WriteLine(); for (int j = 0; j < question_count; j++) { if (answer_sheet[j] == test_answers[j]) { correct_count += 1; } else { Console.WriteLine("Answer {0} is wrong.",j+1); } } Console.ReadKey(); } |
Output: