PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nilios
Forum Newbie
Posts: 2 Joined: Wed Mar 16, 2005 10:35 pm
Post
by nilios » Wed Mar 16, 2005 10:39 pm
before i start pulling out my hair can someone help me with this simple piece of code you've probably all have seen in any php beginner book.
for some reason i am not getting the correct result:
<?php
$x=6;
$y=4;
$z=$x%$y;
print $z;
?>
correct answer -> 5
my answer -> 2
why? maybe someone can help me out here.
thanks.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Mar 16, 2005 11:16 pm
you got the correct answer.. where did the "correct answer" you found come from?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Wed Mar 16, 2005 11:17 pm
x mod y will give you the remainder of the divsion.
so if you divide 6 by 4, you will have 2 as remainder... (6 = 1 * 4 + 2)
thus the correct answer is 2 (and every x that can be written as x * 4 + 2, because they are in the same equivalence class).
nilios
Forum Newbie
Posts: 2 Joined: Wed Mar 16, 2005 10:35 pm
Post
by nilios » Wed Mar 16, 2005 11:20 pm
hey guys,
thanks for the help, i figured it out afterwards and was doing something totally different. need sleep.
later