# dart game

Page 1 of 1

## 3 Replies - 3130 Views - Last Post: 25 October 2013 - 03:50 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=332315&amp;s=e99e3cdc9a031c2aec0d3ccffcd74fde&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 pbivens85

• D.I.C Regular

Reputation: -5
• Posts: 383
• Joined: 22-October 13

# dart game

Posted 23 October 2013 - 09:43 PM

well I have brainstormed this problem. According to my understanding of the problem I have a unit circle within a square. What I want to find is a value that is inside the circle and not outside the circle. There is an area outside the circle but inside the square which is I don't want to find. The value inside the circle is counted as a hit while a value outside the circle and inside the square is counted as a miss. I have determined the area of the unit circle is 3.1415 while the area of the square is 4. This leaves remaining area as 0.86 units. I have amended my code.
```#include <iostream>
#include <math.h>
#include <time.h>

using namespace std;

int main()
{
srand(time(NULL));

float LO=-1.0f;
float HI=1.0f;

for(int i=1; i<=10; i++)
{
float x = LO + (float)rand()/((float)RAND_MAX/(HI-LO));
float y = LO + (float)rand()/((float)RAND_MAX/(HI-LO));

cout << x << endl;
cout << y << endl;

}

system("pause");
return 0;
}

```

as seen above I am generating a random number from -1 to 1 from both the x and y axis. let me know if you need more information.

Is This A Good Question/Topic? 0

## Replies To: dart game

### #2 Skydiver

• Code herder

Reputation: 6116
• Posts: 21,052
• Joined: 05-May 12

## Re: dart game

Posted 23 October 2013 - 10:02 PM

So go back to your basic algebra and recall that all points x,y such that x2 + y2 <= r2 is within the circle of radius r.

### #3 cpricelandscapes

Reputation: 0
• Posts: 2
• Joined: 17-October 13

## Re: dart game

Posted 23 October 2013 - 11:10 PM

It is c programming and I am weak in this portion.

### #4 pbivens85

• D.I.C Regular

Reputation: -5
• Posts: 383
• Joined: 22-October 13

## Re: dart game

Posted 25 October 2013 - 03:50 PM

Skydiver, on 23 October 2013 - 10:02 PM, said:

So go back to your basic algebra and recall that all points x,y such that x2 + y2 <= r2 is within the circle of radius r.

cool well I solved this problem. thanks skydiver for all your help.