I'm trying to write a program that will approximate pi based on a simulation of darts being thrown for a class.

This is what the template code looked like for the assignment:

Code:

#include <iostream> //Required for cin, cout
#include <iomanip> //Required for setting precision
#include <cstdlib> //Required for random numbers
#include <ctime> //Required for system clock reading
using namespace std;
int main()
{
// Declare and initialize objects.
int n; // input -- number of dart throws to simulate
double pi; // output -- approximation of pi
double x, y; // working -- coordinates of dart “throw”
srand(time(0)); //use current time as seed
for ( int count = 1; count <= n; count++ ) {
x = (double) rand()/RAND_MAX;
y = (double) rand()/RAND_MAX;
} //end for loop
// Exit program.
return 0;

This is what I've added in, but I'm not sure what to add in for "pi" on line 23. Any help?

Code:

#include <iostream> //Required for cin, cout
#include <iomanip> //Required for setting precision
#include <cstdlib> //Required for random numbers
#include <ctime> //Required for system clock reading
using namespace std;
int main()
{
//Declare and initialize objects
int n; //input - number of dart throws to simulate
double pi; //output - approximation of pi
double x, y; //working - coordinates of dart "throw"
cout << "How many dart throws would you like to be simulated?" << endl;
cin >> n;
srand(time(0)); //use current time as seed
for ( int count = 1; count <= n; count++ ) {
x = (double) rand()/RAND_MAX;
y = (double) rand()/RAND_MAX;
pi =;
cout << "The approximate value of pi is: " << pi << endl;
} //end of loop
return 0;
}