I am trying to count the number of dice rolls till it reaches to a definite stop value. For example, I want the stop value as 100. I am writing the following code:
sumofsides <- function(stopvalue) {
totalsum <- 0
while (totalsum < stopvalue) {
face <- sample(6, 1, replace= TRUE)
totalsum <- totalsum + face
}
return(total value)
}
sumofsides(100)
[1] 103
When I am writing the following code to get the number of rolling till it reaches to the stop value. But it's always giving value of 1 which is wrong.
numofrolls <- function(stopvalue) {
totalsum <- 0
while (totalsum < stopvalue) {
face <- sample(6, 1, replace= TRUE)
totalsum <- totalsum + face
}
return(length(face))
}
numofrolls(100)
[1] 1
Any help is appreciated.