You are on page 1of 8

Area and Perimeter Calculator Program

Algorithm
Step 1: Start
Step 2: Read opt, opt1, opt2, length, width, radius, side, height, base, a, b, c, area, perimeter
Step 3: Read pi as constant = 3.1416
Step 4: Choice between two cases
1. Area
2. Perimeter
Other input is considered as invalid
Step 5: Both Choices “Area” and “Perimeter” asks about 4 cases after picking between the two
1. Rectangle
2. Circle
3. Square
4. Triangle
Other input is considered as invalid
Step 6: If perimeter is to be solved then
Rectangle is perimeter = 2*(length+width) then print perimeter
Circle is perimeter = 2*pi*radius then print perimeter
Square is perimeter = 4*side then print perimeter
Triangle perimeter = a+b+c then print perimeter but if sides value are in Inequality then
invalid values is printed

If area is to be solved, then


Rectangle is area = length*width then print area
Circle is area = pi*radius*radius then print area
Square is area = side*side then print area
Triangle area = height*base/2 then print area

Step 7: End

Flowchart
Pseudocode

Read opt, opt1, opt2, length, width, radius, side, height, base, a, b, c, area, perimeter,
pi = 3.1416
Write "Welcome, Please choose on what to solve"
Write "1. Perimeter"
Write << "2. Area"
Write << "Your option is?"
Write value of opt

Choices(opt)

case 1:
Write "You chose Perimeter"
Write "What perimeter out of the 4 would you like to get?"
Write "1. Perimeter of the Rectangle"
Write "2. Perimeter of the Circle"
Write "3. Perimeter of the Square"
Write "4. Perimeter of the Triangle"
Write "Your option is?"
Write value of opt1

Choices(opt1)
case 1:
Write "You chose the Perimeter of the Rectangle”
Write "Please enter the width of the Rectangle"
Write value of width
Write "Please enter the length of the Rectangle”
Write value of length

perimeter = 2*(length+width)

Write "The perimeter of the Rectangle is " = perimeter

case 2:
Write "You chose the Perimeter of the Circle”
Write "Please enter the radius of the Circle"
Write value of radius

perimeter = 2*pi*radius

Write "The perimeter of the Circle is " = perimeter

case 3:
Write "You chose the Perimeter of the Square"
Write "Please enter the side of the Square"
Write value of side

perimeter = 4*side

Write "The perimeter of the Square is " = perimeter

case 4:
Write "You chose the Perimeter of the Triangle"
Write "Please enter the value of side a"
Write value of a
Write "Please enter the value of side b"
Write value of b
Write "Please enter the value of side c"
Write value of c

if (a+b>c && c+b>a && c+a>b)


perimeter = a+b+c
Write "The perimeter of the Triangle is " = perimeter

else if (a+b<=c)
Write "The values are not accepted due to the Triangle Inequality Theorem"
Write "Try to check if the values are a+b>c or c+b>a or a+c>b :)"
else if (a+c<=b)
Write "The values are not accepted due to the Triangle Inequality Theorem”
Write "Try to check if the values are a+b>c or c+b>a or a+c>b :)"
else if (c+b<=a)
Write "The values are not accepted due to the Triangle Inequality Theorem”
Write "Try to check if the values are a+b>c or c+b>a or a+c>b :)"

Other options:
Write "The number chosen was not in the options"

case 2:
Write << "You chose Area"
Write "What area out of the 4 would you like to get?"
Write "1. Area of the Rectangle"
Write "2. Area of the Circle"
Write "3. Area of the Square"
Write "4. Area of the Triangle"
Write "Your option is?"
Write value of opt2

Choices(opt2)

case 1:
Write "You chose the Area of the Rectangle”
Write "-----------------------------------"
Write "Please enter the width of the Rectangle"
Write value of width
Write "Please enter the length of the Rectangle”
Write value of length

area = length*width

Write "The Area of the Rectangle is " = area

case 2:
Write "You chose the Area of the Circle"
Write "Please enter the radius of the Circle"
Write value of radius
area = pi*radius*radius;

Write "The Area of the Circle is " = area

case 3:
Write "You chose the Area of the Square"
Write "Please enter the side of the Square"
Write value of side

area = side*side

Write "The Area of the Square is " = area

case 4:
Write "You chose the Area of the Triangle"
Write "Please enter height of the Triangle"
Write value of height
Write "Please enter the base of the Triangle"
Write value of base

area = height*base/2

Write "The perimeter of the Triangle is " = area

Other Options:
Write "The number chosen was not in the options"
Other Options:
Write "The number chosen was not in the options"

End

You might also like