I am creating a code to simulate a simple slot machine. In my function 'slot_machine', I keep getting an issue with my 2nd else if statement
else if (drum1==2|3|4|5 & drum2==2|3|4|5 & drum3==2|3|4|5){
payout <- 114}
Even when the conditions are not met, it keeps making the payout value $114. I'm relativity new to coding so this might be a stupid mistake. If you have any suggestions or ideas, I would greatly appreciate them.
Thank you.
cat("\014")
# d)
slot_machine <- function(payout){
drum1 <- 1
drum2 <- 1
drum3 <- 7
if (drum1==drum2 & drum2==drum3){
if (drum1==1){
payout <- 3000
}
else if (drum1==2|3|4|5){
payout <- 114
}
else{
payout <- 0
}
}
else if (drum1==2|3|4|5 & drum2==2|3|4|5 & drum3==2|3|4|5){
payout <- 114
}
else{
payout <- 0
}
}
number_of_plays <- 5
total_gain = number_of_plays*2
array = rep(NA,number_of_plays)
total_loss <- 0
for (i in 1:number_of_plays){
array[i] <- slot_machine(payout)
total_loss <- total_loss + array[i]
}
profit = total_gain - total_loss