Solved

number checker

Posted on 2008-09-29
8
180 Views
Last Modified: 2012-05-05
hello there,
I would like to create something so that if I give a number lets say (150)
the code checks from 0 until 150 and once it finds it then say "number found!"
0
Comment
Question by:XK8ER
  • 5
  • 3
8 Comments
 
LVL 17

Expert Comment

by:nanharbison
Comment Utility
this should work

<?PHP

$checkthisnumber = $_GET['thisnumber'];
 

$i=1;

while ($i < 151) 

{

	

 if ($i == $checkthisnumber) 

 	{

		echo "number found";

		break;

	}

$i++;

}
 

?>

Open in new window

0
 
LVL 17

Accepted Solution

by:
nanharbison earned 500 total points
Comment Utility
or if you want to show the number

<?PHP

$checkthisnumber = $_GET['thisnumber'];
 

$i=1;

while ($i < 151) 

{

	

 if ($i == $checkthisnumber) 

 	{

		echo "number found, it is: ". $checkthisnumber;

		break;

	}

$i++;

}
 

?>

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
Comment Utility
yes, the last one is good.. how can I make it show a number not found?
0
 
LVL 1

Author Comment

by:XK8ER
Comment Utility
lets say I type number 6 it should be like

1 not found
2 not found
3 not found
4 not found
5 not found
6 number found
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:XK8ER
Comment Utility
ok I think I got it!
$checkthisnumber = '50';

 

$i=1;

while ($i < 151) 

{

        

 if ($i == $checkthisnumber) 

        {

                echo $checkthisnumber . ' number found';

                break;

        }

      			else

        				echo $i . ' not found<br>';

$i++;

}

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
Comment Utility
like this

<?PHP

$checkthisnumber = $_GET['thisnumber'];
 

$i=1;

while ($i < 151) 

{

	

 if ($i == $checkthisnumber) 

 	{

		echo "number found, it is: ". $checkthisnumber;

	} else {

		echo $checkthisnumber." was not found ";

	}

$i++;

}
 

?>

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
Comment Utility
oops, that was wrong

<?PHP

$checkthisnumber = $_GET['thisnumber'];

$checkthisnumber = 100;

$i=1;

while ($i < 151) 

{

	

 if ($i == $checkthisnumber) 

 	{

		echo "number found, it is: ". $checkthisnumber;

	} else {

		echo $i." was not found<br /> ";

	}

$i++;

}
 

?>

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
Comment Utility
use the break statement if you want the loop to stop when the number is found.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now