-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape_areas.php
97 lines (64 loc) · 3.32 KB
/
shape_areas.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
//Declares String Variables
$square = "Square";
$rectangle = "Rectangle";
$triangle = "Triangle";
$circle = "Circle";
$help = "Help";
$quit = "Quit";
echo("\nType 'Quit' to exit program when desired.\n");
$ask = readline("Input the shape to calculate its area. (Please have first letter be uppercase): ");
if ($ask == $quit)
echo("You have quit.\n\n");
while ($ask != $quit) {
if ($ask == $square) // if statement for square
{
// creates square image
echo(" __________\n? |\n? |\n? |\n? |\n?__________|\n");
$squareside1 = readLine("What is the length of one of its sides? "); // get side length
$squareanswer = $squareside1 * $squareside1; // calculates area of square
//creates square image for saying area
echo("\n __________\n| |\n| |\n| |\n| |\n|__________|\n\n");
echo("The area of the square is: "). $squareanswer;
$ask = readline("\n\nInput a shape to calculate its area: "); // prompts user to continue
}
if ($ask == $rectangle) //if statement for rectangle
{
// creates rectangle image
echo(" _______________\n| |\n| |\n| |\n ? ? ? ? ? ? ? ?\n");
$rectangleside1 = readline("What is the length of its base? "); // finds base
echo(" _______________\n? |\n? |\n? |\n?_______________|\n");
$rectangleside2 = readline("What is the length of its height? "); // finds height
$rectangleanswer = $rectangleside1 * $rectangleside2; //calculates area of rectangle
// displays area with image
echo("\n _______________\n| |\n| |\n| |\n|_______________|\n");
echo("The area of the rectangle is: "). $rectangleanswer;
$ask = readline("\n\nInput a shape to calculate its area: "); // promts user to continue
}
if ($ask == $triangle) // if statement for triangle
{
// displays triagnle image
echo(" /\ \n / \ \n / \ \n / \ \n ????????\n");
$trianglebase = readline("What is the length of its base? "); // finds base
echo("? /\ \n? / \ \n? / \ \n? / \ \n? /________\ \n"); // displays image for height
$triangleheight = readline("What is the length of its height? "); // finds height
$triangleanswer = (($trianglebase * $triangleheight)/ 2); // calculates area
// creates image with area
echo(" /\ \n / \ \n / \ \n / \ \n/________\ \n");
echo("The area of the triangle is: "). $triangleanswer; // displays area
echo("\n"); // adds blank line
$ask = readline("\n\nInput a shape to calculate its area: "); // prompts user to continue
}
if ($ask == $circle) // if statement for circle
{
$circleradius = readline("What is the raidus of the circle? "); // finds radius
$circleanswer = ($circleradius * $circleradius) * 3.14; // calculates area
echo("\nThe area of the circle is roughly: "). $circleanswer; // displays area
echo("\n"); // adds blank line
$ask = readline("\n\nInput a shape to calculate its area: "); // prompts user to continue
}
else
echo("\nThe available shapes for this program are Square, \nRectangle, Triangle, and Circle\n");
$ask = readline("\nInput a shape to calculate its area: "); // prompts user to continue
} // end while statement
?>