@Allosaurus
First of all, please PUT YOUR CODE IN CODE TAGS. Look at your post: it is almost unintelligible. You will get many more replies if you make an effort to format your posts in a manner that allows them to be read easily. If you put your code in code tags: (a) we can see the indentation, and hence structure; (b) we can run it directly in the online compiler without having to go through the fuss of copying it.
Please try to explain to someone why you have set c = 5.0. You are specifically asked in the question to use a square of side 2, extending, it would seem, from -1 to 1. Thus, if c seems to be left as a free variable (there is nothing in the question implying that necessity) then c = 1.0
If you ask for the number of darts (N) ... then please don't try to generate 10
N of them! It could take a very long time. TBH it would be simpler just to have N as a single variable input by the user and pass N as an argument to Area_Ellipse, not c. You do NOT need the loop starting
1 2
|
for (int k = 1; k < N; k++) {
totaldarts = pow(10, k);
|
For what is actually given in the question, the following will do (and corresponds to c=1):
double x = -1 + 2.0 * rand() / RAND_MAX;
double y = -1 + 2.0 * rand() / RAND_MAX;
The condition that it lies within the ellipse is OK, if somewhat over-bracketed.
You haven't included a call to srand(), so you will get (for a given N) the same answer each time. That's not random.
The total area of a 2x2 square is 4 units, so if you calculate the fraction that lie in the ellipse (successes/throws, taking care over integer division) then the area of the ellipse will be fraction x (area of square).
Basically, your area routine should deal with one N value only. You should also start small and then build up: make your code work for a single value of N, and later modify it to run for more (if you actually deem that necessary).
Reformat your code taking account of the above, put it in code tags, and re-post BELOW.