Jump to content

Need Help With Multiplication App


MjM8082

Recommended Posts

I have a multiplication app that users will use as a test. The app has 9 multiplication problems that will be filled out. Then when the user hits the score button. It will then display the number of seconds it took to complete test and the answers that were filled out.

 

What I want this app to do is display the ones that the user got wrong along with the correct answer. Not sure how I would do this.

 

Here is my code to the app...

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lab 5</title>
</head>

<body>
<?php
define ('ROWS', 3);
define ('COLS', 3);
define ('MAX_NUMBER', 12);
date_default_timezone_set('America/New_York');

if (isset($_POST['btn_score']))
{
	//print_r ($_POST);
	$time1 = $_POST['ts'];
	$time1_object = new DateTime($time1);
	$now = new DateTime();
	$time_span = $now->diff($time1_object);

	$minutes = $time_span->format('%i');
	$seconds = $time_span->format('%s');
	$seconds+= $minutes * 60;

	echo "It took $seconds seconds to complete the test<hr />";



	foreach ($_POST as $problem => $answer)
	{
		if ($problem <> "btn_score" && $problem <> "ts")
		{
			//echo "$problem -- $answer <br />";
			$problem = explode('_', $problem);
			$num1 = $problem[2];
			$num2 = $problem[3];

			echo "$num1 * $num2 === $answer <br />";
		}
	}
}







?>

<h1>Lab 5</h1>

<form name="lab5" method="post" action="lab5b.php">
<?php
	$now = new DateTime();
	//echo $now->format('Y-m-d H:i:s');
	echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>";
?>
<table border="1" cellspacing="5" cellpadding="5">

<?php


	$no_of_problems = 0;
	for ($row=0; $row<ROWS; $row++)
	{
		echo "<tr>";
		for ($col=0; $col<COLS; $col++)
		{
			$num1 = mt_rand(1,MAX_NUMBER);
			$num2 = mt_rand(1,MAX_NUMBER);

			echo "<td>$num1 * $num2 </td>";
			echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>";
			$no_of_problems++;
		}
		echo "</tr>";
	}
	$colspan = 2 * COLS;
	echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>";
?>	
</table>
</form>

</body>
</html>

 

 

 

Link to comment
Share on other sites

hmmm... just answered the same question in your duplicate post. (you shouldn't do that!!!)

 

anyway, this one says you want the wrong answers along with what should have been the correct answer... so change this line:

echo "$num1 * $num2 === $answer <br />";

to:

if(($num1 * $num2) != $answer) echo "$num1 * $num2 === $answer | Correct answer was: <b>".($num1 * $num2)."</b><br />";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.