Link to home
Start Free TrialLog in
Avatar of clo1
clo1

asked on

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')){
print header, start_html('MATH DRILL PROGRAM'),
h1('Math Drill Program'),
start_form,

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

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

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

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

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

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

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

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

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

"$m[9] * $n[9] = ",
textfield('query9'),
hidden('answer9', $r[9]),
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]');
    $answer[$j] = param('answer[$j]');
  }
 
  for ($k=0; $k<=10; $k++){
    if ($query[$k] == $r[$k]){
      $right = $right + 1;
    }
    else{
      $wrong = $wrong + 1;
    }
  }
 
print header,
      start_html('Math Drill Result'),
      h1, "<PRE>";
print << "END";
Math Drill Program Result:
<HR>
Right Answer = $right
Wrong Answer = $wrong
<HR>
END
print "</PRE>", end_html;
}
   
 
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clo1
clo1

ASKER

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.

But I have checked it has no problem. Please help again. THANKS !
Avatar of ozo
Is "END" the only thing on the line?  or it it really "END  " or "  END"?
Avatar of clo1

ASKER

Yes, it is only "END" as you show me. Did you tried to run it? Do you have any problem?
Avatar of clo1

ASKER

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.