Hi all, I am on Julia 1.1.1 within Jupyter kernel. I wrote a dice program, but I get errors. Not sure what I am doing wrong? I consulted the docs with no gains.
function playcr(bet_amount ::Int64)
die1 = rand(1:6, 1)
die2 = rand(1:6, 1)
roll = die1+die2
if roll == 7 | roll == 11
print("You won!")
return bet_amount
elseif roll == 2 | roll == 3 | roll == 12
print("Woops, you lost.")
return -bet_amount
else
score = roll
print()
print("You rolled a ", score, ".")
roll = diceroll()
while roll != 7 & roll != score
roll = diceroll()
print("Now you rolled a ", roll)
if roll == 7
print("Too bad, you lost.")
return -bet_amount
else
print("You won! Congrats!")
return bet_amount
end
end
end
end
In the above If statements you are testing arrays.
roll is an arrray of length 1
I am not sure what you want, but mayby you want a random scalar, e.g.: die1 = rand(1:6, 1)[1]
PS: here is the corrected version for anyone else new to Julia:
function playcr(bet_amount ::Int64)
die1 = rand(1:6)
die2 = rand(1:6)
roll = die1+die2
if roll == 7 || roll == 11
print("You won!")
return bet_amount
elseif roll == 2 || roll == 3 || roll == 12
print("Woops, you lost.")
return -bet_amount
else
score = roll
print()
print("You rolled a ", score, ".")
while roll != 7 && roll != score
print("Now you rolled a ", roll)
if roll == 7
print("Too bad, you lost.")
return -bet_amount
else
print("You won! Congrats!")
return bet_amount
end
end
end
end