Hi! I am doing a course about the R software and I have a couple of doubts.

In one of the tasks we were asigned, we have to perform a function that
simulates a bus' trip with 25 stops. In each of those stops, between 0 and
6 people can go on board. And when the total of passengers reaches 44, no
more people can go on board.

stops <- 25

passengers <- 0

register <- numeric(25)

bus <- function(register,stops,passengers) {

register[1] <- passengers

for (i in 1:stops) {

passengers <- passengers + sample(0:6,1)

register[i] <- passengers

}

  # If the bus isn't full:

  if (passengers >= 44) {

    # Adjustment if it reaches 44 passenger, before the 25th stop:

    register[i:stops] <- 44

    cat('Full bus!\n') # Warning message...

    break

} else {

  # If the loop doesn't stop, a new register must be added:

  register[i] <- passengers

}

  # Para ir viendo cuánto hay:

  cat('Stop', i, 'hay', passengers, 'passenger\n')

}

plot(register, xlab='Stop', ylab='No. of passengers')

The parts of the script that are marked in sky blue, are the ones that we
have to fill up, so on of those should be my mistake.

I would be very glad, if anyone can detect my error, as I have been many
days stuck on this part and my deadline is tomorrow.

Thx a lot in advance to everyone.

Wanda

BTW: Sorry for my English! My native language is Spanish! :)

	[[alternative HTML version deleted]]

