samedi 14 avril 2018

PHP comparing random numbers

I am basically using the rand function to generate 2 random numbers i am then running the two random numbers thorough an if statement saying if the player guesses correctly +1 to the score for some reason while I'm passing these numbers through the statements and I'm getting wrong results, I'm getting the wrong results because I'm using print_r to identify what numbers are going in and what numbers are going out. Ive tried creating sessions for the numbers and that didn't change a thing can anybody offer me a couple of minuets of there time to just take a quick look im going out my mind. Thankyou very much

<?php 
$PlayerCard =  rand (1,52);
$Cardrand = rand (1,52);
print_r($PlayerCard);
 echo "<br>";
print_r($Cardrand);



 if (isset($_GET['Higher'])) {
  if ($Cardrand>$PlayerCard) {
    $Score++;
    print_r($PlayerCard);
    echo "<br>";
    print_r($Cardrand);

  }
  else {
    $Score=0;
      print_r($PlayerCard);
      echo "<br>";
      print_r($Cardrand);
  }
  $_SESSION['Score'] = $Score;

  }



  if (isset($_GET['Lower'])) {
    if ($Cardrand<$PlayerCard) {
     $Score++;
     print_r($PlayerCard);
     echo "<br>";
     print_r($Cardrand);


  }
     else {
        $Score=0;
        print_r($PlayerCard);
        echo "<br>";
        print_r($Cardrand);
  }
        $_SESSION['Score'] = $Score;

  }


   if (isset($_GET['NewDeal'])) {
      $Score=0;
      $PlayerCard = rand (1,52);
      $Cardrand = rand (1,52);
      $_SESSION['Score'] = $Score;
  }




Aucun commentaire:

Enregistrer un commentaire