I am trying to create a simple macro for optimization problems that must (as per the publisher) compile with LaTeX2e. I want the macro to look like the example below in terms of usage (the actual processing of constraints is more complicated, but I tried to eliminate distracting details; this was the simplest example that I could find that produced an error). I obviously need to record when the first constraint is added so that subsequent constraints do not print "subject to". However, when I add any of the three commented lines below, LaTeX tells me that the ifnum is incomplete. Additionally, if I change the second argument of setcounter to 1, then I do not receive an error (although the behavior is not correct). What is the problem here?
\documentclass{article}
\usepackage{amsmath}
\newcounter{opc}
\newcommand{\optimizationproblem}[3]
{
\setcounter{opc}{1}
\begin{array}{ll}
\text{#1} & #2 #3
\end{array}
}
\newcommand{\constraint}[1]
{
\ifnum \value{opc} = 1
%\setcounter{opc}{0}
\\ \text{subject to} & #1
%\setcounter{opc}{0}
\else
\\ #1
\fi
%\setcounter{opc}{0}
}
\begin{document}
\begin{equation*}
\optimizationproblem
{minimize}
{c^{T} x}
{
\constraint{A x = b}
\constraint{x \geq 0}
}
\end{equation*}
\end{document}

