I am trying to use a Piecewise function to calculate values and then convert these values to Currency objects-- so far, I'm not getting it to work. When the answer is submitted it is scored as incorrect and the message is displayed: "Unexpected charactoer '$' " The code I've gotten so far is listed below.

Thanks -- rac

-----------------------------------------------------------------------------------

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"contextCurrency.pl",

"contextPiecewiseFunction.pl"

);

TEXT(&beginproblem);

######################################

# Setup

Context("PiecewiseFunction");

$x1 = random(5000,7000,1000);

$x2 = random(8000,12000,1000);

$m1 = random(.02,.04,.01);

$m2 = $m1 + random(.02,.04,.01);

$b2 = $m1*$x1;

$m3 = $m2 + random(.01,.02,.01);

$b3 = $b2+$m2*($x2-$x1);

$T = Formula("$m1 x if x <= $x1

else $b2 + $m2 (x -$x1) if $x1 < x <= $x2

else $b3 + $m3 (x -$x2) if x > $x2");

Context("Numeric");

$input = random(4000,15000,10);

$tax = $T->eval(x=>$input)->inContext(Context());

Context("Currency");

$income = Currency($input);

#####################################

# Main text

BEGIN_TEXT

Suppose the state income tax for a single person in 2005 was

determined by the rule

\[ T(x) = \{$T->TeX\} \]

where \(x\) is the taxable income for a single person. Find the tax due on the income:

$PAR

For $income the tax = \{ans_rule(15)\}

END_TEXT

######################################

# Answers

ANS(Currency($tax)->cmp);

######################################

ENDDOCUMENT();