## WeBWorK Problems

### wierd earning ### wierd earning

by Carl Yao -
Number of replies: 6
Hello:

The following is a fairly easy problem involving radio buttons. This is the line which is causing problem:

$choice0 =$a1*$b; I don't understand why WeBWorK gave me a warning: ## WeBWorK Warnings WeBWorK has encountered warnings while processing your request. If this occured when viewing a problem, it was likely caused by an error or ambiguity in that problem. Otherwise, it may indicate a problem with the WeBWorK system itself. If you are a student, report these warnings to your professor to have them corrected. If you are a professor, please consult the warning output below for more information. ### Warning messages • Use of uninitialized value$value in string eq at line 314 of [PG]/macros/parserRadioButtons.pl
• Use of uninitialized value $value in string eq at line 314 of [PG]/macros/parserRadioButtons.pl Thank you for any help! Carl Yao Portland Community College # WeBWorK problem written by Carl Yao # Portland Community College # # Estimate the product of multiplication like 2856*4 # # Last edited: Carl Yao 10/13/2016 # DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGML.pl", "parserRadioButtons.pl", "PGcourse.pl", ); ###################################### TEXT(beginproblem()); Context("Numeric");$a = random(2,9,1);
$b = random(2,7,1);$a1Exp = random(2,4,1);
$a1Ten = 10**$a1Exp;
$a1 =$a*$a1Ten;$a1Close = $a1+10**($a1Exp-1)*non_zero_random(-2,2,1)+10**($a1Exp-2)*non_zero_random(-2,2,1);$choice0 = $a1*$b;
$choice1 = ($a-1)*$a1Ten*$b;
$choice2 = ($a+1)*$a1Ten*$b;
$choice3 =$choice0*10;

$radio = RadioButtons( [$choice0,$choice1,$choice2,$choice3],$choice0, #correct
);

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

BEGIN_PGML

Without using a calculator, round the first number to a number easier to calculate, and then estimate the product.

[ [$a1Close] \cdot [$b] \approx ? ]

[@ $radio->buttons() @]* END_PGML ############################################################ ANS($radio->cmp() );

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

BEGIN_PGML_SOLUTION

The correct answer is [[@ $radio->correct_ans() @]*]. END_PGML_SOLUTION ###################################### ENDDOCUMENT(); In reply to Carl Yao ### Re: wierd earning by Alex Jordan - The error message refers to the eq operator, which is for comparing strings. Reading the documentation for parserRadioButtons.pl, it sounds as if the choices are assumed to be strings. (https://github.com/openwebwork/pg/blob/master/macros/parserRadioButtons.pl) So you might try making your choices be strings instead of perl reals.$radio = RadioButtons(
["$choice0","$choice1","$choice2","$choice3"],
"$choice0", #correct ); P.S. I don't know the motivation behind the problem, but is multiple choice needed? In reply to Alex Jordan ### Re: wierd earning by Carl Yao - Hi Alex: Thanks for the reply. I added quotation marks, but the error is still there... The reason to use radio buttons is that this is an estimation problem. Students could round 2812 to 3000, or simply 2800. By using radio buttons, I force students to round 2812 to 3000 before doing multiplication. Carl Yao In reply to Carl Yao ### Re: wierd earning by Alex Jordan - Got it, after reading the code for parserRadioButtons.pl. There is a feature that is interfering with your intent. If the second argument of RadioButtons is a nonnegative integer, like say 2, then that is supposed to be a shortcut for declaring the 2nd (third, starting the count from 0) array entry to be the correct answer. Your correct answer is 300000, so you are unintentionally asking it to take the 300000th choice as the correct answer. This array entry has not been defined of course, and that explains the error message "use of uninitialized value...". So if your choices actually are nonnegative integers, you *have* to use this shortcut. Instead of$choice0 as the correct answer, you just need to use 0, since that is the index of $choice0 in [$choice0,$choice1,$choice2,\$choice3]. ### Re: wierd earning

by Carl Yao -
Mystery solved! :) Thank you!

Carl Yao ### Re: wierd earning

by Paul Pearson -
Hi,

I recently asked Davide Cervone about this.  I think he may have updated parserRadioButtons.pl to fix this in the github version.  As a work around, Davide suggested answers such as " 300000 " (notice the extra spaces) instead of "300000".  The extra spaces should mean that the it gets interpreted as a string, not a number.  This work around is probably the safest way to fix the problem (the work around should be backward and forward compatible).

Best regards,

Paul Pearson 