mardi 30 janvier 2018

If statement within an if statement not working

Im just learning about if statements and now im trying to create a little blackjack kinda game. But the error of "Error: unexpected '}' in "}"" keeps comming up, and I cannot solve the problem. This is my current code

#Dealer: If the sum of the cards is lower than 17, the dealer must draw another card 
n_3 = 2
A = 11
#Deck: 
deck <- c(A,A,A,A,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,8,8,8,8,7,7,7,7,6,6,6,6,5,5,5,5,4,4,4,4,3,3,3,3,2,2,2,2)
roll_3 <- sample(deck, n_3, replace = T)
roll_3 
sum(roll_3)

###
#Dealers game
###
if(sum(roll_3) < 17 ){
  newcard = sample(deck,1,replace = T)
  total_dealer_1 <- c(newcard + sum(roll_3))
  #print(sum(roll_3)+newcard)
    if (total_dealer_1 < 17){
      newcard_2 = sample(deck,1,replace = T)
      total_dealer_2 <- c(newcard_2 + total_dealer_1)
     else if (total_dealer_2 > 21) {
        paste("The dealers score is", total_dealer_2,",the dealer busted!")
    } else if (total_dealer_2 < 21 & total_dealer_2 >= 17) {
        paste("The dealer got",total_dealer_2,"!")
    } else if (total_dealer_2 < 17){
        newcard_3 = sample(deck,1,replace = T)
        total_dealer_3 <- total_dealer_2 + newcard_3
     
        
          if (total_dealer_3 > 21) {
            paste("The dealers score is",total_dealer_3,", the dealer busted!")
          } else (total_dealer_3 <= 21) {
            paste("The dealers score is", total_dealer_3)
          }
      }
    }

} else if ((sum(roll_3) < 21 & sum(roll_3) >= 17)) {
    paste("The dealers score is", sum(roll_3))
} else if (sum(roll_3 == 21)){
  paste("21!", "The dealer got backjack!")
}

Been trying for hours now...

Aucun commentaire:

Enregistrer un commentaire