Homework help please
Posted: Thu Oct 16, 2008 10:32 pm
Hello,
I'm having trouble with one of my exercises from my book and I was hoping something could help me out please. I'm not looking for you to do it for me but I'm really confused and it's an online class. The teacher isn't that much help. The Exercise is: "Write a program that lets the user choose how many sides a die will have and print out a random roll with the appropriate maximum values (don't worry about using images to display the dice)." I read the chapter and understand the examples that they gave but they don't seem thorough enough to do the exercise. My problem is that the form shows up but the "HERE;" and all the php below it also shows up. I would appreciate your help. I really want to get through this class and finally learn php.
Thank you,
Holly
I'm having trouble with one of my exercises from my book and I was hoping something could help me out please. I'm not looking for you to do it for me but I'm really confused and it's an online class. The teacher isn't that much help. The Exercise is: "Write a program that lets the user choose how many sides a die will have and print out a random roll with the appropriate maximum values (don't worry about using images to display the dice)." I read the chapter and understand the examples that they gave but they don't seem thorough enough to do the exercise. My problem is that the form shows up but the "HERE;" and all the php below it also shows up. I would appreciate your help. I really want to get through this class and finally learn php.
Thank you,
Holly
Code: Select all
<html>
<head>
<title>Die Sides</title>
</head>
<body>
<?php
$die = 0;
$integer = 0;
extract($_REQUEST);
print <<<HERE
<form>
<h4> Pick which die to roll and press ROLL: </h4>
<input name="die" type="radio" value="100" />6 sides<br>
<input name="die" type="radio" value="200" /> 9 sides<br>
<input name="die" type="radio" value="400" /> 12 sides<br>
<input name="die" type="radio" value="1776" /> 14 sides<br>
<input name="die" type="radio" value="45" /> 24 sides<br>
<input value = "ROLL" type = "submit">
</form>
HERE;
if ($die > 0) {
print "You got $die";
}
switch ($die){
case 6:
$integer = rand(1,6);
break;
case 9:
$integer = rand(1,9);
break;
case 12:
$integer = rand(1,12);
break;
case 14:
$integer = rand(1,14);
break;
case 24:
$integer = rand(1, 24);
break;
}
if (!empty($integer)) {
print "<p>You rolled $integer !</p>";
$die = 0;
}
?>
</body>
</html>