include './navi/sidebar.php'; ?> <div class="CONTENT" id="COINTOSS"> <h1>Coin Toss Program</h1> <p>Whenever two battlers have the same speed, the originator of the battle must flip a coin in order to determine the player that will be able to attack first. This is a simple program that simulates the coin toss, because I know on occassion, sometimes you can't find a coin when you need one!</p> <p>Please remember Eorl's Honor battle code when using this program.</p> <ul> <li> <b>Battle with honor</b>.�Never lie about stats or coin flips.�Always follow proper rules and procedure. </li> </ul> <table> <tr> <th>Your Coin Toss Result is...</th> </tr> <tr> <td> <?php coinToss(); ?> </td> </tr> </table> <div class="LINK_BACK"> <p>Back to <a href="../index.php">Index</a></p> </div> </div> <?php include 'footer.php';
Staring from 0, all prices come from column 4 in the table/array; starting from 0, the first number refers to each string of the $bookData array.*/ echo "<p>"; echo "Your total price is: \$" . ($bookData[1][4] + $bookData[2][4] + $bookData[3][4] + $bookData[4][4] + $bookData[5][4] + $bookData[6][4]); echo "</p>"; ?> <h1>Challenge: Coin Toss, continued</h1> <?php /*Repeat the coin exercise from HW2, but modify your program to 1) Be a function that takes one argument – the number of heads in a row you'd like to flip 2) Modify your code to use this argument to allow a variable number of heads in a row to be chosen You should print out the number of heads in a row you are seeking and the total number of flips it took. */ $headsFlipped = 8; coinToss($headsFlipped); function coinToss($headsFlipped) { $previousFlip = 8; $totalFlips = 0; $heads = 0; echo "Beginning the coin flipping, looking for {$headsFlipped} heads in a row....<br>"; while ($headsFlipped != $heads) { $recentFlip = mt_rand(0, 1); $totalFlips++; /*1 of mt_rand = heads; if $recentFlip = 1, count of $heads increases by 1*/ if ($recentFlip == 0) { echo "<img src='http://i1383.photobucket.com/albums/ah299/rikkiap202/lincoln%20penny%202010_zpsqyqxsmzr.jpg' height='100', width='100'>"; } else { echo "<img src='http://i1383.photobucket.com/albums/ah299/rikkiap202/lincoln%20penny%202010%20-%20Copy_zps4najflyw.jpg' height='100', width='100'>"; }