...

View Full Version : My random number script....



LRmaster
03-06-2003, 05:44 PM
I decided to add a if fuction, where if the random number was 1 more or less than the guess something else will be printed. There is a problem, and when it does get to 1 more/ less, it just says that it is wrong. My script is:

<?php
$Guess = 3;
$Between1 = 1;
$Between2 = 10;
$Number = rand($Between1,$Between2);
print ("
<center>

The number is...
<font color=green><b>$Number</b></font>
<p><p>Your guess was...
<font color=green><b>$Guess</b></font><p><p>

</center>
");
if ($Guess == $Number) {
$Correct = Yes;
print ("<center>You got it correct!</center>");
} elseif ( ("$Guess - 1" > $Number) or ("$Guess + 1" < $Number) ) {
$Correct = No;
print ("<center>You got it wrong!</center>");
} elseif ($Number == "$Guess +- 1")
$Correct = Nearly;
print ("<center>You got it nearly correct!</center>");
}
print ("<p>");
if ($Correct == Yes) {
print ("<center>You win 700 Credits!</center>");
} elseif ($Correct == No) {
print ("<center>You win 0 Credits!</center>");
} elseif ($Correct == Nearly) {
print ("<center>You win 500 Credits!</center>");
}

?>

Please post if you can fix it

Spookster
03-06-2003, 06:53 PM
if($Guess == $Number){
$Correct = "Yes";
print ("<center>You got it correct!</center>");
}
elseif(($Guess == $Number-1) || ($Guess == $Number+1)){
$Correct = "Nearly";
print ("<center>You got it nearly correct!</center>");
}
else{
$Correct = "No";
print ("<center>You got it wrong!</center>");
}

print ("<p>");

if ($Correct == "Yes") {
print ("<center>You win 700 Credits!</center>");
}
elseif($Correct == "Nearly") {
print ("<center>You win 500 Credits!</center>");
}
else{
print ("<center>You win 0 Credits!</center>");
}

LRmaster
03-06-2003, 06:57 PM
It works, thank you :o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum