Why is the part of this script doing the math.tan - work, not functioning properly?
It returns that "a" is equal to a negative number, when it is supposed to be 0.577, why?
How can I fix this?
My coding is as follows:
function CalculateArea(s,n) --// s = side-length, n = number of sides local p = s*n local a = math.tan(180/n) --//Supposed to return 30 when n == 6, but it doesn't :-/ print(a) end CalculateArea(10,6)
Any help is greatly appreciated!
Your issue is that math.tan
is expecting an Angle in radians, not degrees.
You can convert between radians and degrees using math.rad
(degrees -> radians) and math.deg
(radians -> degrees), but based on your code it's just as easy to change the 180
degrees into math.pi
radians:
function CalculateArea(s,n) local p = s*n local a = math.tan(math.pi/n) print(a) end CalculateArea(10,6)
Okay Follow My instructions 1. put that script In the workspace folder then un arrow It.2 then put it in starter guide