Petals Around the Rose
Demonstrates variable scope
$guess = $_REQUEST["guess"];
$numPetals = $_REQUEST["numPetals"];
printGreeting();
printDice();
printForm();
function printGreeting() {
global $guess, $numPetals;
if (isset($guess)){
if ($guess == $numPetals) {
print "You got it Right!!
";
} else {
print <<from last try:
you guessed: $guess
-and the correct answer was: $numPetals petals around the rose.
HERE;
} //end if
} else {
print "Welcome to Patals Around the Rose
";
} //end isset if
} //end printGreeting
function printDice() {
global $numPetals;
print "New Roll:
";
$numPetals = 0;
$die1 = rand(1,6);
$die2 = rand(1,6);
$die3 = rand(1,6);
$die4 = rand(1,6);
$die5 = rand(1,6);
showDie($die1);
showDie($die2);
showDie($die3);
showDie($die4);
showDie($die5);
print "
";
calcNumPetals($die1);
calcNumPetals($die2);
calcNumPetals($die3);
calcNumPetals($die4);
calcNumPetals($die5);
} // end printDice
function showDie($value) {
print <<
HERE;
} //end showDie
function calcNumPetals($value) {
global $numPetals;
switch ($value) {
case 3:
$numPetals += 2;
break;
case 5:
$numPetals += 4;
break;
} //end switch
} //end calcNumPetals
function printForm() {
global $numPetals;
print <<How many petals around the rose?
HERE;
} // end printForm
?>