Random number Question

This is a discussion on Random number Question within the PHP forums in Programming Languages category; On Saturday 13 March 2010 11:54, Jennifer Downey wrote: > Hi all, > > I having a hard time understanding why this won't work. I have a form which > is suppose to pass the guess to the script. Here it is: It's no good just telling us it doesn't work. You need to tell us what happens when you run it. Error messages? Blank screen? -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* "355/113 -- Not the famous irrational number PI, but an incredible simulation!" */...

Go Back   Application Development Forum > Programming Languages > PHP

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 03-12-2002, 10:59 PM
Jason Wong
Guest
 
Default Re: [PHP] Random number Question

On Saturday 13 March 2010 11:54, Jennifer Downey wrote:
> Hi all,
>
> I having a hard time understanding why this won't work. I have a form which
> is suppose to pass the guess to the script. Here it is:


It's no good just telling us it doesn't work. You need to tell us what
happens when you run it. Error messages? Blank screen?


--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
"355/113 -- Not the famous irrational number PI, but an incredible
simulation!"
*/
Reply With Quote
  #2  
Old 03-12-2002, 11:00 PM
Balaji Ankem
Guest
 
Default RE: [PHP] Random number Question

Try Now:

<form action="number.php" method="post">
The computer has picked a number between 1 and 10. Guess the number and
you win!<BR>


Enter your guess:
<input type="text" name="guess" value="" size="3">
<INPUT TYPE="submit" VALUE="Submit my number" NAME="submit"> </form>

-----Original Message-----
From: Jennifer Downey [mailto:jendowney@attbi.com]
Sent: Saturday, March 13, 2010 9:25 AM
To: php-general@lists.php.net
Subject: [php] Random number Question


Hi all,

I having a hard time understanding why this won't work. I have a form
which is suppose to pass the guess to the script. Here it is:

the form is guess.php:

<form action="number.php" method="post">
The computer has picked a number between 1 and 10. Guess the number and
you win!<BR>


Enter your guess:
<input type="text" size="3">
<INPUT TYPE="submit" VALUE="Submit my number" NAME="guess"> </form>


The script is number.php:

<?php
echo"The number is:";

srand((double)microtime()*1000000);
$number = rand(1,10);

echo $number;

if($guess = = $number) {
echo"<BR>You have won!";
}else{
print("<BR>Sorry that wasn't the answer");

}
?>

Any help would be appreciated.

Thanks in advance
Jennifer Downey



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Reply With Quote
  #3  
Old 03-13-2002, 02:50 PM
Ralph Friedman
Guest
 
Default Re: Random number Question

In article <20020313035421.28517.qmail@pb1.pair.com>, Jennifer Downey wrote:

> <input type="text" size="3">
> <INPUT TYPE="submit" VALUE="Submit my number" NAME="guess">
>

you've got the "Name" attribute attached to the wrong INPUT element:

<INPUT type="text" size="3" name="guess">
<INPUT type="submit" value="Submit my number">

> if($guess = = $number) {
>

incorrect syntax here. that should be:
if ($guess == $number) {

better would be:

if (trim($guess) == $number {

this will assure that there's no whitespace in $guess

--
Rgds
Ralph


Reply With Quote
  #4  
Old 04-02-2002, 08:52 PM
Hiroshi Ayukawa
Guest
 
Default Re: [PHP] Random number Question

$guess = = $number
is wrong.

You should write:
$guess == $number


Regards,
Hiroshi Ayukawa
http://hoover.ktplan.ne.jp/kaihatsu/...x.php?type=top
Reply With Quote
  #5  
Old 04-18-2002, 03:54 PM
Joel Colombo
Guest
 
Default Re: Random number Question

actually

if (intval($guess) == $number {

would be more acuate then the trim ( )
you would eliminate all alpha characters and floating points
saying it has to be a whole integer....

Joel



"Ralph Friedman" <ralph@friedman-net.com> wrote in message
news:VA.00000005.0285e606@friedman-net.com...
> In article <20020313035421.28517.qmail@pb1.pair.com>, Jennifer Downey

wrote:
>
> > <input type="text" size="3">
> > <INPUT TYPE="submit" VALUE="Submit my number" NAME="guess">
> >

> you've got the "Name" attribute attached to the wrong INPUT element:
>
> <INPUT type="text" size="3" name="guess">
> <INPUT type="submit" value="Submit my number">
>
> > if($guess = = $number) {
> >

> incorrect syntax here. that should be:
> if ($guess == $number) {
>
> better would be:
>
> if (trim($guess) == $number {
>
> this will assure that there's no whitespace in $guess
>
> --
> Rgds
> Ralph
>
>



Reply With Quote
  #6  
Old 04-29-2002, 11:36 AM
Dan Koken
Guest
 
Default Re: Random number Question

Try something like this and see if it works???
================================================== ==
<?
$another = 'a';
if (isset($guess)) $another = 'another';
echo "
<form action='number.php' method='post'>
<BR>
The computer has picked $another number between 1 and 10.<BR>
Guess the number and you win!<BR>
<BR>
Enter your guess:
<input type='text' size='3'>
<INPUT TYPE='submit' VALUE='Submit my number' NAME='guess'>
</form>";

if (isset($guess))
{
srand((double)microtime()*1000000);
$number = rand(1,10);

echo "The number is: $number<BR>";

if ($guess == $number)
{
echo '<BR>You have won!';
}else{
echo "<BR>Sorry that wasn't the answer";
}
}
?>

================================================== ===============


Jennifer Downey wrote:

> Hi all,
>
> I having a hard time understanding why this won't work. I have a form which
> is suppose to pass the guess to the script. Here it is:
>
> the form is guess.php:
>
> <form action="number.php" method="post">
> The computer has picked a number between 1 and 10. Guess the number and you
> win!<BR>
>
>
> Enter your guess:
> <input type="text" size="3">
> <INPUT TYPE="submit" VALUE="Submit my number" NAME="guess">
> </form>
>
>
> The script is number.php:
>
> <?php
> echo"The number is:";
>
> srand((double)microtime()*1000000);
> $number = rand(1,10);
>
> echo $number;
>
> if($guess = = $number) {
> echo"<BR>You have won!";
> }else{
> print("<BR>Sorry that wasn't the answer");
>
> }
> ?>
>
> Any help would be appreciated.
>
> Thanks in advance
> Jennifer Downey
>
>
>


Reply With Quote
  #7  
Old 04-29-2002, 11:51 AM
Dan Koken
Guest
 
Default Re: Random number Question

OOPS!
You are right on..
I noticed my error after I sent it. The name='guess' was on the input.??
Daaa! it's Monday .. OK!!
This should work:
================================================== =
<?
$another = 'a';
if (isset($guess)) $another = 'another';
echo "
<form action='number.php' method='post'>
<BR>
The computer has picked $another number between 1 and 10.<BR>
Guess the number and you win!<BR>
<BR>
Enter your guess:
<input type='text' size='3' NAME='guess'>
<INPUT TYPE='submit' VALUE='Submit my number'>
</form>";

if (isset($guess))
{
srand((double)microtime()*1000000);
$number = floor(rand(1,10));

echo "The number is: $number<BR>";

if ($guess == $number)
echo '<BR>You have won!';
else echo "<BR>Sorry that wasn't the answer";

}
?>

Reply With Quote
  #8  
Unread 03-12-2010, 10:54 PM
Jennifer Downey
Guest
 
Default Random number Question

Hi all,

I having a hard time understanding why this won't work. I have a form which
is suppose to pass the guess to the script. Here it is:

the form is guess.php:

<form action="number.php" method="post">
The computer has picked a number between 1 and 10. Guess the number and you
win!<BR>


Enter your guess:
<input type="text" size="3">
<INPUT TYPE="submit" VALUE="Submit my number" NAME="guess">
</form>


The script is number.php:

<?php
echo"The number is:";

srand((double)microtime()*1000000);
$number = rand(1,10);

echo $number;

if($guess = = $number) {
echo"<BR>You have won!";
}else{
print("<BR>Sorry that wasn't the answer");

}
?>

Any help would be appreciated.

Thanks in advance
Jennifer Downey


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 10:22 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.