Classic Computer Magazine Archive COMPUTE! ISSUE 61 / JUNE 1985 / PAGE 76


C. Regena

Multiple Choice Test

I've seen a number of computer programs written for multiple choice tests. The computer is an ideal way to administer such tests because it can mix up the test questions so each run is different. However, all the programs I have seen always print the choices in the same order. This month's program is a general-purpose multiple choice tester that randomly arranges both the questions (without repetition) and the possible answers.

This program can be used for questions on any topic. Computer literacy questions are included here for an example.

The questions and answers are in DATA statements. Each DATA statement contains six items. The first item is the question; the next four are the possible answers; and the last item is the number of the correct answer. The final DATA statement signals the end of the question list:

1350 DATA ZZZ,Z,Z,Z,Z,0

You may use any number of possible questions that will fit in the computer's memory. Line 190 is a DIMension statement that allows for 30 possible questions. To increase the number of questions, change all the 30s in line 190.

Reading The Data

Line 160 defines the number of questions in the test, and line 300 performs the procedure for the specified number of questions. If you want to alter this number, change the 20 in these two lines plus the printed score in line 690. Also make sure you have as many or more questions and answers in the DATA statements as you want in the test.

The variable I is used as a counter for the questions. Questions read from the DATA statements are stored in the string variable T$, the four possible answers are stored in A$, and the number of the correct answer is stored in B. These values are in arrays to keep the answers with the corresponding questions.

As the information is being read in, S$(I) is set equal to A for use as a signal so questions won't be repeated during the quiz. When a question X is printed, S$(X) is set equal to "" (null). Line 320 chooses a random number X, but if S$(X) is null, the question has previously been used and a different X must be chosen. Line 350 prints the question.

Lines 370–390 define C(J) for the four answers to mix up the order in which the answers are printed. Line 400 randomly chooses D for the correct answer. The C variable for the correct answer is set to zero so it cannot be used in another position. Lines 430–490 mix up the order of the answers, making sure the correct answer is in the right position and each answer is used only once. Lines 500–530 print the four answers with the possible choices A, B, C, and D.

Lines 540–580 receive the student's answer, making sure it is a letter from A to D, and then print the choice. Line 590 checks to see if the key pressed is the correct choice. Line 600 prints the message for an incorrect answer, then prints the correct answer. Line 620 prints CORRECT for a correct answer, and line 630 increments the score, SC. Lines 640–670 wait for the student to press ENTER before going to the next question.

Lines 680–700 clear the screen, then print the score.

To customize the test, simply change the questions and answers in the DATA statements, making sure you have enough questions for a complete quiz and that the last DATA statement contains ZZZ to signal the end. You might also prefer a fancier title screen.

Here is an example of changing the DATA statements. Suppose your question is "In which year did Columbus discover America?" with the possible answers 1256, 1492, 1776, and 1812. The correct answer is in the second position. The DATA statement would look like this:

730 DATA 1256,1492,1776,1812,2