0

I want to calculate marking points for an exam by multiplying a percentage with the total number of points (e.g., 0.5 * \numpoints{}) to make a grading table. Problem is that before I run the compilation I cannot access \numpoints as a number and get an error. I have been trying to use some sort of if-statement to solve it but that has rendered nothing useful. A working example is below, my current solution is to comment these lines, compile the file and then uncomment and compile again. Is there an easy way to use an if-statement to solve this issue?

\documentclass[addpoints, 12pt]{exam}
\printanswers
\usepackage[utf8]{inputenc}
\usepackage{fp}

\begin{document}
\Large{Exam}\\

% Marking points COMMENT line 1-3 below to run first time
\FPeval{\gradethree}{clip(\numpoints{} * 0.5)}
\FPeval{\gradefour}{clip(\numpoints{} * 0.67)}
\FPeval{\gradefive}{clip(\numpoints{} * 0.83)}

% Marking table COMMENT lines 2-4 below to run first time
\noindent{}Total points: \numpoints{} \\
Grade 3:  \gradethree \space points \\
Grade 4:  \gradefour  \space points \\
Grade 5:  \gradefive  \space points \\

\begin{questions}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\end{questions}


\end{document}

The output after my comment workaround looks like this (which is exactly what I want to achieve): Exam with marking table and answers

1 Answer 1

0

The package ifthenx which offers the \ispositiveinteger function does the trick:

\documentclass[addpoints, 12pt]{exam}
\printanswers
\usepackage[utf8]{inputenc}
\usepackage{fp}
\usepackage{ifthenx}

\begin{document}
\noindent\Large{Exam}\\

% calculates marking points for exam grades
\ifthenelse{\ispositiveinteger{\numpoints}}
    {   \FPeval{\gradethree}{clip(\numpoints{} * 0.5)}
        \FPeval{\gradefour}{clip(\numpoints{} * 0.67)}
        \FPeval{\gradefive}{clip(\numpoints{} * 0.83)}  }

% grading table:
\noindent{}Total points: \numpoints{} \\
\ifthenelse{\ispositiveinteger{\numpoints}}
    {   Grade 3:  \gradethree \space points \\
        Grade 4:  \gradefour  \space points \\
        Grade 5:  \gradefive  \space points \\  }
    % Printed if \numpoints is not available.
    {Sorry no grading table \textbf{yet}.}
    
\normalsize
\begin{questions}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\question[2]
Who is Mark Twain?
\begin{solution}
Not your daddy.
\end{solution}

\end{questions}


\end{document}

Gives of course the same output as above when numpoints exists, otherwise prints that the marking table is not available.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .