I'm trying to use multiple conditions in an IF statement, to see if the number entered was 5, 10, or 15. If the input is not one of these numbers, then it should output an error message.
But even if 5, 10, and 15 are input, it always outputs the error message.
when 3
print("Enter the discount percentage, must be (5, 10, or 15)")
dis= gets.to_i
if (dis != 5 || dis != 10 || dis != 15)
puts("You entered an invalid discount")
else
end
to_i, not_i.p || qis the same as!(!p && !q)(from De Morgan's Law). So your expression is the same as!(dis == 5 && dis == 10 && dis == 15). The expression within the parentheses is obviouslyfalsefor any value ofdis, so!(false) #=> true, causingputsto be executed regardless of the value ofdis.