Hallo,
Ik ben bezig met een programmatje voor informatica om opdrachten met hexadecimaal rekenen te doen maar nu stuit ik op het volgende probleem, het controleren van het antwoord.
De functie om decimale getallen om te zetten naar hexadecimale getallen:
<?php
function dec_to_hex($dec)
{
$sign = "";
$h = "";
if( $dec < 0){ $sign = "-"; $dec = abs($dec); }
$hex = Array( 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5,
6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 'A',
11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E',
15 => 'F' );
do
{
$h = $hex[($dec%16)] . $h;
$dec /= 16;
}
while( $dec >= 1 );
return $sign . $h;
echo $sign;
}
?>
Hier loop ik vast:
<?php
$rand = rand(1,66535);
echo $rand;
?>
<br>
<br>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post">
Antwoord: <input name="antwoord" type="text">
<br>
<br>
<input type="submit" name="Submit" value="Controleren!">
</form>
<?php
if ($_POST["antwoord"] == dec_to_hex($rand)) {
echo "Het antwoord is goed"; }
else { echo "Het antwoord is fout"; }
?>
als ik bij "if ($_post["antwoord etc. etc." invul == dec_to_hex(10) ofzow en ik vul dan als antwoord A in dan werkt het gewoon, dus het zit 'm ergens in de variabele $rand
graag tips want ik zit helemaal vast
1.849 views