# How to count the number of questions separately for different parts in exam class?

I am creating an exam with two parts, the first part is short questions and the second part is essay question, and I would like to automatically count the number of questions for the two parts separately. By default, the \numquestions displays the total number of questions in the document.

\documentclass{exam}

\begin{document}

\begin{questions}
\fullwidth{\Large \textbf{Short questions}}
There are \numquestions\ short questions. %display the number of short questions.

\question
This is the first short question.
\question
This is the second short question.

\setcounter{question}{0}

\fullwidth{\Large \textbf{Essay questions}}
There are \numquestions\ essay questions. %display the number of essay questions.

\question
This is the first essay question.
\question
This is the second essay question.
\question
This is the third essay question.
\question
This is the fourth essay question.
\end{questions}
\end{document}

-
Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. A suggestion: Do us a favour and change your username to something more telling than "jc2254". – Martin Schröder Oct 21 '13 at 8:06

Here is a solution using the totcount package and redefining the \question command with \squestion for the short questions and \equestion for the essay questions.

\documentclass{exam}

\usepackage{totcount}

\newtotcounter{s}
\setcounter{s}{0}
\newtotcounter{e}
\setcounter{e}{0}
\newcommand{\squestion}[0]{\stepcounter{s}\question}
\newcommand{\equestion}[0]{\stepcounter{e}\question}

\begin{document}

\fullwidth{\Large \textbf{Short questions}}
There are \total{s}\ short questions. %display the number of short questions.

\begin{questions}
\squestion
This is the first short question.
\squestion
This is the second short question.
\end{questions}

\setcounter{question}{0}

\fullwidth{\Large \textbf{Essay questions}}
There are \total{e}\ essay questions. %display the number of essay questions.

\begin{questions}
\equestion
This is the first essay question.
\equestion
This is the second essay question.
\equestion
This is the third essay question.
\equestion
This is the fourth essay question.
\end{questions}

For the record there is a total of \numquestions\ questions.

\end{document}


And here is the output:

Note The \numquestions command hasn't been modified so that you can still use it if you need to have the total number of questions (both short ones and essay ones).

-