Jump to content

Posting a Random Number With If Statements.


JayLewis

Recommended Posts

Hey my problem is:

 

The user types in there name and hits sumbit. Then i use this code to generate a random number. I want an If statement for example "49% = "Under 50%" and "51%+ = 50% Plus"

 

I am using this code to do so, but the If statements seems to be random also.

 

You and <?php echo $_POST["name"]; ?> are 
		<? srand((double)microtime()*1000000);  
echo rand(0,100);
echo "% compatible!";

$number = rand(0,100);

if ($number < 49) {

echo "</b><br>Under 50%";



}

else {

echo "</b><br>50% Plus";

}


?>

You're getting two random number, when (I think) you only want one:

<?php
echo 'You and ' . $_POST["name"] .' are';  
$number = rand(0,100);
echo $number . '% compatible!';
if ($number < 50) 
echo "</b><br>Under 50%";
else
        echo "</b><br>50% Plus";
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.