OK yes I’m an idiot…
Here’s the part of the code I’m having trouble with:
for ($cointoss = rand(1,2); $toss = $toss;) {
if ($cointoss = 1) {
$heads = 1;
print "Number of heads, $heads
";
}
else {
$tails = 2;
print "Number of tails, $tails
";
}
}
//end of my crapy code...
I’ve already set the $toss in the form. It’s giving me an infinite loop or whatever. What I’m tryin to do is have the user type in the number of tosses they want it to do (which is going to be defined as $toss) and then have it count how many heads and tails in total and out put it back to the user. Like “Number of heads, 10” “Number of tails, 10” “You flipped the coin 20 times”. That kinda thing.
Please don’t give me the answer straight up, it’s for class I don’t want to cheat. What I want is some help as to what the hell I’m doing wrong. The teacher tried explaining it to me, but I didn’t get it and I REALLY had to be somewhere so I didn’t ask for a clarification. PLEASE someone help me!!!!!!
2007-02-26
07:35:30
·
5 answers
·
asked by
Am
4
in
Computers & Internet
➔ Programming & Design
Now I'm getting:
"Parse error: syntax error, unexpected T_WHILE in C:\Inetpub\wwwroot\lab4.php on line 38
"
Here's my code now:
if (empty($toss)) {
print <<
HERE;
}
else {
$cointoss = rand(1,2);
$atoss = 0
while ($atoss < $toss;) {
$atoss++;
if ($cointoss == 1) {
$heads = 1;
print "Number of heads, $heads
";
}
else {
$tails = 2;
print "Number of tails, $tails
";
}
}
print <<
flip coin again
HERE;
}
?>
2007-02-26
08:13:04 ·
update #1
I changed it to a while ... and I tried out the == ...
but yeah...
Um, I'll try what that dude said about just making it count 10 flips, maybe if I get it to do that then I can figure out what I NEED it to be doing ... I'll post up the stuff again soon ... thx 4 the help ;-)
2007-02-26
08:14:32 ·
update #2
OR ...
What about:
/*
changed again but now it's back at a never ending loop AHhhhhhhh!
*/
else {
for ($cointoss = rand(1,2); $toss == $toss;) {
if ($cointoss = 1) {
$heads = 1;
$heads++;
print "Number of heads, $heads
";
}
else {
$tails = 2;
$tails++;
print "Number of tails, $tails
";
}
}
// end of code
2007-02-26
08:19:07 ·
update #3
ok I'll brb I'm gonna make it just freakin count ...
2007-02-26
08:20:02 ·
update #4