I am using the below code to find how many iterations it takes for the confidence interval to become approximately 25. However, when I run it it stops with interval lengths which do not fit the criteria. They are close, but not between 24.99 and 25.01.
counter <- 0
r <- 50
while((r-25)>0.01){
counter <- counter + 1
a <- replicate(500,profit())
CI_l <- mean(a) - (sd(a)/sqrt(500))*qnorm(0.975)
CI_u <- mean(a) + (sd(a)/sqrt(500))*qnorm(0.975)
r <- CI_u-CI_l
}
cat("It took ", counter, " tries to get to an interval of", r)
I am sure that there are also easier ways to do this but my main concern is whether R is doing something wrong or I am.