# Thread: Area of Circle Without Pi

1. ## Area of Circle Without Pi

Hi,

I am new to the forums and new to C++ and need some help. I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.

I've spent hours trying to figure out how to get this done and so far this is what ive come up with but I don't know what im doing wrong... If someone could please help me out id greatly appreciate it!

Code:
```#include<iostream>
#include<cmath>

using namespace std;

int main ()
{
// Initialize
double radius, difference, newvalue, oldvalue, area, n(2), i, square;

cout << "Enter the radius of the circle...\n";

difference = abs(((newvalue - oldvalue/oldvalue)))*100;

// Summon Loop
while (difference <= 0.1)
{
for (i=1; i==n; i++) {

newvalue += square;

}

// Check Loop
difference = abs(((newvalue - oldvalue)/oldvalue))*100;

if (difference > 0.1) {
oldvalue=newvalue;
}

n++;

}
// Result
area = 2*newvalue;

cout << "\nThe estimated area of the circle is: " << area << endl;

system("pause");
return(0);

}```

2. If computing the areas of multiple rectangles to estimate the area of a circle, you need to make sure the rectangles don't overlap.

Adding up the areas of overlapping rectangles will give an area that exceeds the area they actually cover.

3. That makes sense... Is there something in my code I need to remove or add to prevent this from happening? This is all very new to me and I just wanna pass my midterm .... Thanks!

4. Also... Dont know if it helps but these are the equations I was given...

Area under a curve.... y=√(r^2-x^2 )

Margin of Error..... % Error=|(New Value-Old Value)/(Old Value)|×100%

Finding the area of the recatangles.... ∆X=r/n

5. I wouldn't do it by rectangles. I would do it using 2^n triangles.
Initially calculate 4x the area of a triangle that covers 1/4 of the area, using Heron's Formula.
Then each iteration step, split the triangle into half its size, project the new point to the circumference, calculate the new area of the smaller triangle using 8x the area given by Heron's formula.
The attached image shows the second and third iterations.
etc.

6. Thanks... I appreciate the help, and while using triangles seems a lot more understandable and easy to me, this being my midterm, I'd rather learn what I'm doing wrong and correct it, then modify the assignment that was given.

7. Jhernandez860- do you have the completed C++ program?

8. Do not bump threads. (Bumping: Posting messages on threads to move them up the list or to post on a thread that has been inactive for two weeks or longer).
Announcements - C++ Programming

The purpose of these board is not for other people to do your homework for you. Try things out work on your own, homework has a purpose. If you still have trouble with a specific piece of code or concept please feel free to ask. But please do not ask people to do your entire homework for you, it simply annoys people most of the time.
Announcements - General Programming Boards