0
Im flipping 2 coins 100 times in a while loop and want to know how many times i hit: Tails, Tails, or Head,Tails, or Head, Head.
7 odpowiedzi
+ 2
<html>
<head>
<title>Coins</title>
</head>
<body>
<?php
$heads = $tails = $both = 0;
for ($i = 0; i < 100; i+=1)
{
$coin1 = rand(0, 1);
$coin2 = rand(0, 1);
if ($coin1 & $coin2) $heads += 1;
if (!($coin1 & $coin2)) $tails += 1;
else $both+=1;
}
echo("Heads: $heads");
echo("Tails: $tails");
echo("Both: $both");
?>
</body>
</html>
+ 2
This is wrong. let me fix it
+ 1
Yeah I'm a bit "rusty" on PHP 😂
0
Thanks a lot!
0
I noticed, but it worked, although I wanted to know specifically how many: Tails,Tails. Heads,Heads and tail,head/head,tail there are.
0
I'm a noob :V, just could not figure out how to count all the possibilities, managed to flip all the coins though.
0
I am also having trouble with the coin toss