I'm working a project and I'm hitting some trouble along the way in the directions. I'm supposed to be implementing Monte Carlo methods in the function in order to properly run it, however the steps I am following are worded weirdly and I'm having trouble understanding. Any pointers in the right direction would be greatly appreciated. I'll leave the directions and what I have written in the code so far below. Thanks.
-CC
Directions:
Tasks:
Write a program that prompts the user to input the number of samples. Then generate that
many random points from the domain x = [0, 1], y = [0,1] and calculate and print an estimate of
Pi. Follow the pseudocode below:
declare an integer variable to count the number of samples which fall in the circle and
initialize it to 0
declare double variables x and y
prompt the user to input the number of samples
loop number of samples times
set x equal to a random number between 0 and 1
set y equal to a random number between 0 and 1
if the square root of (x * x + y * y) is less than 1, then the point we chose
randomly is within the circle, so increment the variable counting samples in the
circle
end of loop
Print the estimate of pi, which is 4 times (number of samples found inside the
circle)/(total number of samples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
int main(int argc, const char * argv[]) {
int samp = 0;
double x = 0.0, y = 0.0;
int count = 0;
std::cout << "Please enter the number of samples: " << std::endl;
std::cin >> samp;
for (count = 0; count < 0; count++)
double x = [0,1]
double y = [0,1]
if ((x * x + y * y) > 0)
|