[조건]
컴퓨터가 1부터 10사이의 정수를 랜덤 값으로 선택하고, 저장하도록 한다.
그리고 당신이 1에서 10사이의 정수를 선택한다.
컴퓨터가 선택한 랜덤값과 당신의 값을 비교하고 당신의 숫자가 더 높은 경우 "Down", 당신의 숫자가 더 낮은 경우는 "Up", 당신의 숫자와 동일한 경우 "Bingo"가 출력되도록 하라.
// 1
var computerChoice = Int.random(in: 1...10)
var myChoice = 5
var x = computerChoice - myChoice
if x == 0 {
print("Bingo!")
} else if x > 0 {
print("Up")
} else {
print("Down")
}
// 2
var computerChoice = Int.random(in: 1...10)
var myChoice = 5
var x: Int = computerChoice - myChoice
switch x {
case _ where x == 0:
print("Bingo!")
case _ where x > 0:
print("Up")
case _ where x < 0:
print("down")
default:
break
}
// 3
var computer = Int.random(in: 1...10)
var me = 5
if computer > me {
print("up")
} else if computer < me {
print("down")
} else {
print("Bingo")
}