use strict;
use warnings;
#finds prime numbers between two points;
print "Please enter the values for the 2 numbers between which you wish to
find the primes.\n";
$x=; chomp($x); print "\n"; #user inputs point x;
$y=; chomp($y); print "\n"; #user inputs point y;
for($i==$x; $i==$y; $i++){
$even=0;
$notprime=0;
$j=$i/2;
if(int($j)==$j){
$even=1; # tests to see if it is even;
}
else{
$n=$i**(1/2);
for($m=3; $m=$n; $m+=2){
$o=$i/$m;
if(int($o)==$o){
$notprime=1;
}
}
}
if($even==0 && $prime==0){
print "$i is prime!\n";
}
}
$q=; # stops the program from closing...;
If anyone wants to help me figure out what's wrong... just let me know what you did?
Thanks.
Thanks!
You say "my interpreter won't stay open long enough to tell me; it closes right when the program finishes"
I guess you are running the program by double clicking the .pl file. Try opening a command (cmd) window and running the program there.
See also perldoc perldebug
--
Oh Lord, wont you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, wont you burn me a Knoppix CD ?
(Missquoting Janis Joplin)
Just for starters,
You should really put
use strict;
use warnings;
at the top of your program. This will save you lots of grief, even though you'll have to start declaring your variables.
You still have the for wrong. I suggest you re-read the documentation.
for($i==$x; $i==$y; $i++)
should be
for(my $i=$x; $i==$y; $i++)
(my added as a bonus)
Or if you want to include $y,
for(my $i=$x; $i<$y; $i++)
But why not use the easier to read/understand/write
for my $i ($x..$y-1)
Or if you want to include $y,
for my $i ($x..$y)
By the way, you're assuming (i.e you don't validate) that the user supplies integers for $x and $y, and that the number he supplied for $x is smaller than or equal to $y.