# Part 5: consecutive errors¶

The automatic correction of generic TeX problems can take into account consecutive errors. This feature is only available for questions of type input.number or input.function. Consider a problem with several questions, all of them of type input.number or all of them of type input.function. Assume the solution of the n-th question depends on the solution of the m-th question for some question numbers m,n with m < n. Say the student's solution of the m-th question was wrong. Then the student used a wrong input for the n-th question. Assume that, apart from starting with a wrong input, the student solved the n-th question correctly. This is what we call a consecutive error. Taking into account consecutive errors means the student doesn't get the points for the m-th question, but the solution of the n-th question is counted as correct and the points are awarded.

Taking into account consecutive errors works as follows. The questions are corrected one after the other. For each question, the following happens:

1. First, the question is corrected normally, meaning the student's solution is compared to the correct solution.
2. If the student's solution coincide with the correct solution, everything is ok and the correction proceeds to the next question.
3. Otherwise, the correction of this question is repeated with certain variables bound to student answers of previous questions. This is called conditional correction. Which variable is bound to which answer is controlled by the author using the \earlierAnswer command described below.
4. The score resulting from the conditional correction is compared to that of the normal correction. The correction with the higher score counts.

The \earlierAnswer command has the following form:

\earlierAnswer{VARIABLE}{QUESTION_NUMBER,ANSWER_NUMBER}

where VARIABLE is the name of the variable defined on global (not question or answer) level, QUESTION_NUMBER the number of the question and ANSWER_NUMBER the number of the answer.

If another variable depends on a variable that is referenced in \earlierAnswer, the dependent variable must also be defined in the global (and not in a question/answer) variable environment.

The answer number and the comma before it can be omitted:

\earlierAnswer{VARIABLE}{QUESTION_NUMBER}

In that case, the answer number defaults to 1.
Optionally you can set the QUESTION_NUMBER to -1 to refer to a previous answer in the same question. This is needed when you for example use \randomquestionpool at the begin of a problem to make a selection:

\earlierAnswer{VARIABLE}{-1,ANSWER_NUMBER}

The \earlierAnswer command is only allowed in the "variables" environment of a question.

Do not use the command \earlierAnswer to refer to an earlier question in a problem that has \randomquestionpool enabled! Problems with random question pools can only use \earlierAnswer for subtasks within the same question, by using the value -1 for the question number.

Below is a complete example of a problem. The problem is trivial: a random number Q is given, and the studend has to compute x = Q + 1 in the first question, y = x + 1 in the socond, and z = y + 1 in the third. The second and third question depend on the solutions of previous questions. To take this into account, we added \earlierAnswer commands to bind variables to earlier answers. In the second question, for example, we bound x to the first answer of question 1.

\usepackage{mumie.genericproblem}

\title{Scratch}

\begin{problem}

\begin{variables}
\randint{Q}{-4}{4}
\function{x}{Q+1}
\function{y}{x+1}
\function{z}{y+1}
\end{variables}

\begin{question}
\text{\textbf{Step 1}\\ \textit{Let Q = $\var{Q}$. Compute x = Q + 1:}}
\type{input.number}
\precision{3}
\field{real}

\text{ x = }
\solution{x}
\end{question}

\begin{question}

\begin{variables}
\end{variables}

\text{\textbf{Step 2}\\ \textit{Compute y = x + 1:}}
\type{input.number}
\precision{3}
\field{real}

\text{ y = }
\solution{y}

\end{question}

\begin{question}

\begin{variables}
\end{variables}

\text{\textbf{Step 3}\\ \textit{Compute z = y + 1:}}
\type{input.number}
\precision{3}
\field{real}