简体   繁体   English

以百分比计算总分数

[英]calculate total score in percentage

<?php
$value1 = rand (1,10);
$value2 = rand (1,10);
?>
<form action="mathq.php" method="post">

<input type="text" name="input1a" value="<?php echo $value1; ?>" class="value" />

<input type="text" value="x" class="equa" />

<input type="text" name="input2a" value="<?php echo $value2; ?>" class="value" />

<input type="text" value="=" class="equa" />

<input id="answer" type="text" name="answer" value="" class="answer" /><br /><br />




<input type="submit" value="Submit answer" class="submit">

<INPUT TYPE="RESET" VALUE="Clear all fields of this form">

</form>

<?php

if(isset($_POST['input1a']) && isset($_POST['input2a']) && isset($_POST['answer'])) {

$result = $_POST['answer'];
$input1a = $_POST['input1a'];
$input2a = $_POST['input2a'];


if (!empty($input1a) && !empty ($input2a) && !empty($result)) {
    //echo '<span class="success">Success!&nbsp;&nbsp;';

}
     if ($result == $input1a * $input2a)
    {
        print($input1a . ' x ' . $input2a . ' = ' . '<span class="correct">' . $result . '</span>' . '<br />Correct!');

    }
    else
    {
        print($input1a . ' x ' . $input2a . ' = ' . '<span class="incorrect">' . $result . '</span>' . '<br />Wrong!<br /> The correct answer was: ' . '<span class="correct">' . $input1a * $input2a . '</span>');
    }

}
?>

I was wondering how i could calculate total score of right answers after the user hits the submit button? 我想知道在用户单击“提交”按钮后如何计算正确答案的总分? How could i create a loop that would go through the rand number of problems and after it goes through once it exits and outputs the person score as percentage of right or wrong answers. 我该如何创建一个循环,解决所有问题,一旦退出并输出人的分数作为对或错的百分比,就可以解决。 I'm stuck on this part. 我被困在这一部分。

I was also thinking of another way i could tackle this problem. 我也在考虑可以解决这个问题的另一种方法。

A user goes through the rand number of math problems once he is done with practices problem he or she hits Done button and it outputs his score. 一旦用户完成了他或她单击“完成”按钮的练习问题,就会经历大量的数学问题,并输出分数。 Can you give me guidance how i can do this? 你能给我指导我该怎么做吗? Thanks. 谢谢。

You need a place to store data whilst questions are in progress. 在进行问题时,您需要一个存储数据的地方。

This would commonly be done in Session data, or in a local database. 通常,这可以在会话数据或本地数据库中完成。 It could be done in cookies, but not advisable. 可以用Cookie进行,但不建议这样做。 It could also be done in a flat text file. 也可以在纯文本文件中完成。

You'd need to count how many questions done, how many right answers, and you can then derive the resulting % to feed back to the user. 您需要计算已完成的问题数,正确的答案数,然后才能得出所产生的百分比以反馈给用户。

Without somewhere to store the intermediate data, you cannot do this. 如果没有地方存储中间数据,则无法执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM