3 Replies - 655 Views - Last Post: 25 October 2013 - 03:50 PM Rate Topic: -----

#1 pbivens85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • 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  Icon User is online

  • Code herder
  • member icon

Reputation: 3460
  • View blog
  • Posts: 10,669
  • 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.
Was This Post Helpful? 1
  • +
  • -

#3 cpricelandscapes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 pbivens85  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 22-October 13

Re: dart game

Posted 25 October 2013 - 03:50 PM

View PostSkydiver, 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1