I need to make a game that the user puts in an answer. The program shows 5 numbers randomly generated and an answer is submitted and then shows another problem and tells the user if they are correct or incorrect.
Here is my code so far and it is just always printing incorrect answer. Dont know what I am doing wrong...
<?php
if( !isset($_GET['answer']) ) {
$n1 = rand (1, 10);
$n2 = rand (1, 10);
$n3 = rand (1, 10);
$n4 = rand (1, 10);
$n5 = rand (1, 10);
}
else {
$num = $_GET['start'] > 14 ? $_GET['start'] - 7 : rand(29,99);
}
?>
<?php print "$n1 + $n2 + $n3 + $n4 + $n5 = ?<br/>"; ?>
<form action="" method="GET">
<input type="text" name="answer" /><br />
<input type="hidden" name="start" value="<?php print $num; ?>" />
<input type="submit" value="Submit" /><br />
</form>
<?php
if( isset($_GET['answer']) ) {
if( $_GET['answer'] == ($_GET['start']) ) {
print 'Correct answer!';
} else {
print 'Incorrect answer.';
}
}