Probability hotel reservations 
A hotel has 100 rooms, and charge guests for their rooms in advance. The number of reservations for tomorrow night is denoted as $n$. Rooms are held until 10pm, but if a guest hasn't shown up by 10pm, then the booking is canceled, and the hotel keeps the booking charge. The hotel has learned from past experience that the probability that any booked guest actually shows up by 10pm is $p = 19/20$, and that hotel guests show up (or not) independently from one another. Let $X$ denote the number of booked guests who show up before 10pm.


Suppose the hotel earns 50 dollars in profit for every guest and no-show, but has to pay a compensation of 60 dollars to each guest who is unable to stay due to overbooking. Assuming the demand for pre-booked rooms is unlimited, how many rooms should be sold to maximize the expected profit?

So we have that $P(X=k)={n \choose k}(p)^k\times(1-p)^{n-k}$. I am having trouble trying to create a profit function. My first attempt was
$$v(X) = \begin{cases} 50n-60(X-100) & X > 100\\ 50n & X \leq 100 \end{cases}$$
However, to maximize payoff, it seems that the hotel would need a proper understanding of exactly who will show up, which is random. This function also does not seem to capture the probability of guests showing up, which should weight what choices the hotel will make. What type of profit function will take into the probability of guests showing up?
 A: Your profit function is correct. What you want to maximize here is the expected profit, that is:
$$\mathbb E[v(X)]=\sum_{x=1}^n p(X=x)\cdot v(x)$$
We can write a R script to optimize this function:
# function to find expected profit if they book n rooms
expected_profit <- function(n){
  X = seq(0,n)
  prob = dbinom(X, size=n, prob=19/20)
  profit = ifelse(X>100, 50*n-60*(X-100), 50*n)
  return(sum(prob*profit))
}

# plotting that function
plot(
  seq(1,400),
  unlist(Map(expected_profit, seq(1,400))),
  type="l"
  )

# finding the maximum
which.max(unlist(Map(expected_profit, seq(1,400))))

This gives the result $n=108$. That is, they optimize their average profit by booking 108 rooms.
A: It is obvious that the optimum number of bookings yielding maximum profit must be greater than the number of available rooms (i.e. 100). Thus, we only need to search for the optimum booking number with $n > 100$.
$Average Profit(n)$
$= 50n - 60\sum_{k=101}^n (k-100){n \choose k}p^k\times(1-p)^{n-k}$.
This gives the optimum booking number 108 for $p=0.95$, same as provided above by PedroSebe.
