# Math Drill Program Problem

I have written a program which will have 10 "10-times table" question, generated by the random number which is range from 1-10. And when the "Submit" button had pressed, the screen will shows up the number of Right and Wrong answer. But I keep having problem on the result screen. The following is my code, can you guys experts help me. Thank you very much !!

P.s. Is there any way to use the "for" loop to display the question part. So I don't need to type it 10 times as it shown below. Thanks again !
========================================
#!c:\Perl\bin\perl
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);

for (\$i = 1; \$i <= 10; \$i++){
\$num1 = int(1 + rand 10);
\$num2 = int(1 + rand 10);

push @m, \$num1;
push @n, \$num2;
push @r, \$num1 * \$num2;
}

if (!param('query0')){
h1('Math Drill Program'),
start_form,

"\$m[0] * \$n[0] = ",
textfield('query0'),
p,

"\$m[1] * \$n[1] = ",
textfield('query1'),
p,

"\$m[2] * \$n[2] = ",
textfield('query2'),
p,

"\$m[3] * \$n[3] = ",
textfield('query3'),
p,

"\$m[4] * \$n[4] = ",
textfield('query4'),
p,

"\$m[5] * \$n[5] = ",
textfield('query5'),
p,

"\$m[6] * \$n[6] = ",
textfield('query6'),
p,

"\$m[7] * \$n[7] = ",
textfield('query7'),
p,

"\$m[8] * \$n[8] = ",
textfield('query8'),
p,

"\$m[9] * \$n[9] = ",
textfield('query9'),
p,

submit('Submit Answer'), reset('Start Over'), end_form, end_html;
}
else{
\$right = 0;
\$wrong = 0;

for (\$j=0; \$j<=10; \$j++){
\$query[\$j] = param('query[\$j]');
}

for (\$k=0; \$k<=10; \$k++){
if (\$query[\$k] == \$r[\$k]){
\$right = \$right + 1;
}
else{
\$wrong = \$wrong + 1;
}
}

start_html('Math Drill Result'),
h1, "<PRE>";
print << "END";
Math Drill Program Result:
<HR>
<HR>
END
print "</PRE>", end_html;
}

LVL 2
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Here you go:

#!c:\Perl\bin\perl
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);

if (!param('query1')){
h1('Math Drill Program'),
start_form;

for (\$i=1; \$i <= 10; \$i++) {

\$num1 = int(1 + rand 10);
\$num2 = int(1 + rand 10);

print "\$num1 * \$num2 = ", textfield("query\$i"), hidden("answer\$i", \$num1 * \$num2), p, "\n";

}

print submit('Submit Answer'), reset('Start Over'), end_form, end_html;
}
else{

\$right = 0;
for (\$j=1 ; \$j <= 10; \$j++){
}

\$wrong = 10 - \$right;

start_html('Math Drill Result'),
h1, "<PRE>";
print << "END";
Math Drill Program Result:
<HR>
<HR>
END
print "</PRE>", end_html;
}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
It is excellent. I am so appreciate for your affort, Thanks.

But one thing is when I run the program, it shows up this error message.

Can't find string terminator "END" anywhere before EOF at c:/program files/apache group/apache/cgi-bin/Testing.pl line 33.

0
Commented:
Is "END" the only thing on the line?  or it it really "END  " or "  END"?
0
Author Commented:
Yes, it is only "END" as you show me. Did you tried to run it? Do you have any problem?
0
Author Commented:
I just found out it is the problem of some of the hidden characters which generated when I copy from the browser to my editor. Thanks for you help. I am appreciate about that.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.