Jump to content

xxplosions

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by xxplosions

  1. So for instance if I wanted 1-100 would it be as follows or am I understanding that incorrectly? '/100|[1-9][0-9]{1}|[1-9]/'
  2. If I wanted to change the upper bound at all on the preg_match would I just change the 1000? Or would I have to do more than that? I've never really used preg_match at all so if you have a link that explains how it works that would be appreciated.
  3. oh ok, my bad, didn't quite grasp that one. So the only thing it prevents is them from changing the number is that what you're referring about?
  4. Thank you very much for the help with this code. I really do appreciate the help. It definitely makes sense the approach that you guys took to make this code work. For this particular instance I don't need to use session variables because the security isn't a risk, but I understand that it's better to do to prevent injection. Either way I appreciate all the help. I'll be sure ask if I have any other questions about this. Again I appreciate the time you took to help me out
  5. well yeah that is a simple method to do it, but I want to make sure that the computer does it in the most efficient way as possible. So something to the effect of they guess 50 initially then if it's high or low they go 50% +/- the previous guess. so if it were too low then they would guess 75, if that's too low then they would guess half way between 75 and 100, and continue on. The previous guess if it's not right becomes the new lower or higher bound. Does that make more sense, and how would the hidden fields cause some issues with that?
  6. I have been working on a PHP guess number game. The version where the person has to guess is finished and works fine, the code is below. What I need to do is convert the code so that the computer guesses the number. I know the basic concept that i need to go about it but need help coding it from the other perspective. If anybody has suggestions of how to go about it that would be much appreciated. <?php $guess=$_POST["guess"]; $counter=$_POST["counter"]; $number=$_POST["number"]; if(empty($number)){ echo "<h4>Welcome! I have a number between 1 and 100. Please guess it.<h4>\n"; $number=rand(1,100); $counter=0; } else { if($number==$guess){ $counter++; echo "<h4>Well done! You guessed $number in $counter steps.<h4>\n"; } if($guess<$number){ $counter++; echo "<h4>Too low. Guess a higher number<h4>\n"; } if($guess>$number){ $counter++; echo "<h4>Too high. Guess a lower number<h4>\n"; } } echo <<<HERE <form method="post" action="guessNum.php"> <input type = "hidden" name = "number" value = "$number"> <input type = "hidden" name = "counter" value = "$counter"> <input type = "text" name = "guess" value = ""> <input type="submit" value="Guess"> </form> HERE; ?>
×
×
  • 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.