I have an assignment which deals primarily with the computation of various factors of regular polygons. The task is as follows:

"Finish writing the following program. Don't make any changes to the main body: all work should be within the PROCEDURES and FUNCTIONS. The program shows a menu asking the user to choose one of the six regular polygons (an equilateral triangle, a square, a regular pentagon, a regular hexagon, etc). It then asks the user for the length of one side of the chosen figure. It then calculates the perimeter, the longest distance across, and the area of the figure, and outputs these to screen. It repeats this until the user decides to quit.

Here's the main body of the program. Complete it by writing the program declarations, including all the procedures and functions referred to in the main body.

BEGIN {main body}

REPEAT

ShowMenu;

choice := GetChoice;

CASE choice OF

1: Triangle(side, perimeter, across, area);

2: Square(side, perimeter, across, area);

3: Pentagon(side, perimeter, across, area);

4: Hexagon(side, perimeter, across, area);

5: Septagon(side, perimeter, across, area);

6: Octagon(side, perimeter, across, area);

7:

END; {of CASE}

IF choice <> 7 THEN BEGIN

write('Side = ' side:8:2);

write('Perimeter = ' perimeter:8:2);

write('Across = ' across:8:2);

write('Area = ' area:8:2) END;

UNTIL choice = 7;

END.

"

I have attempted to use the following formula (obtained from:

http://forum.swarthmore.edu/dr.math/faq/formulas/faq.regpoly.html) to solve for the area of any given regular polygon:

area := n*(s*s)*(((cos((360/n)/2))

/(sin((360/n)/2)))/4);

where n = no. of sides, and s = length of side.

In a step-by-step logical computation, this formula (confusing as it is) should work (substitute values and you'll see). However, as Pascal gives the result of sin and cos as radian rather than degree values, it does not.

perimeter of the object is given by:

perimeter := s*n

Any sort of clarification as to working Pascal formulae for the object's area and longest distance across would be extremely welcome.

I'm new to how all this works so please get in touch with me to clarify anything.

Thanks.

thecomputing@consultant.com
longest distance (d) for

even n: d=s/sin(pi/n)

odd n: d=s*sin((n-1)pi/2n)

/ sin(pi/n)

scrapdog: for equilateral triangle the longest length is s, not s*sqrt(3)/2