Code:
#include <stdio.h> /* standard input and output */
#include <math.h>
#include <stdlib.h> /* srand() */
#define SEED 10000000 /* number of throws at dartboard */
int main (){
int darts; /* number of darts thrown */
double x, y, z, pi; /* x and y are the first quadrant points, z is the square of x and y, pi is used approximate pi */
int p, count=0; /* p stands for number of hits inside the quadrant */
printf("Enter a seed value: \n"); /* user inputs a seed value */
scanf("%d", &darts); /* gets seed value from user and feeds it into number darts thrown */
srand(darts); /* random number generator */
count=0; /* sets initial counting to 0 */
for (p=0; p<SEED; p++){
x=rand(), y=rand();
if (x<0) x=-x;
if(y<0) y=-y;
z=((x*x)+(y*y)); /* square of distance to origin */
}
if (z<=1) count++;{
pi=(double)count/darts*4;
printf("PI is approximately %.2f \n", pi);
return 0;
}
}
This is what i have but the output is now: PI is approximately 0.00.
How would i get the output to be PI is approximately 3.14 for any seed value?