profit_calc.php
<?php $page_title = "Calculating Profit"; include ('includes/header.php'); $pnd = "£"; $answer = $_POST['answer']; /*if (!defined($income && $costs)) { }*/ if (!isset($_POST['answer'])) { $income= number_format(rand(50, 30000),1); $costs= number_format(rand(100, 20000),1); } else { $income_new = $income; $costs_new = $costs; } ?> <div id="spacer"></div> <div id="title" class="text1"><h1><?php echo $page_title ?></h1></div> <div id="spacer"></div> <div id="question" class="text2"> <p>If a company makes a total turnover of <?php echo $pnd.$income; ?> and all the costs come to <?php echo $pnd.$costs; ?>.</p> <p>What is the total profit made by this company?</P> <?php $profits= number_format($income_new-$costs_new, 1); if (!empty($_POST['answer'])) { number_format($answer, 1); if ($answer == $profits) { echo '<div class="correct"></div>'; } else { echo '<div class="incorrect"></div>'; } } else { $answer = NULL; echo "Enter in your answer below."; } ?> </div> <div id="spacer"></div> <div id="submit_box"> <form action="profit_calc.php" method="POST" name="form"> <input type="text" size="12" name="answer"> <div id="input_submit"><input type="submit" name="submit" value="SUBMIT"></div> </form> </div> <script type="text/javascript" language="JavaScript"> document.forms['form'].elements['answer'].focus(); </script> <?php include ('includes/footer.php'); ?>
So basically I want this script to randomly generate two numbers that are then taken away from each other to give you another value. This value will then be validated and display whether you got it right or not. The bit I am struggling with is to get the randomly generated number to follow through to the validation of the actual answer itself. How would I go about doing this. Thank you in advance.