프로그래밍/Golang
Golang Guessing game 게싱게임
CHIqueen
2020. 6. 6. 01:30
package main
import(
"fmt"
"math/rand"
"time"
)
func main(){
fmt.Println("Guessing game")
rand.Seed(time.Now().UnixNano())
secNum := rand.Intn(100)
var guess int
for {
fmt.Scan(&guess)
fmt.Println("You guessed", guess)
if guess < secNum {
fmt.Println("Up")
} else if guess > secNum {
fmt.Println("Down")
} else {
fmt.Println("Correct!")
break
}
}
}
간단한 Go 언어 예제
math/rand와 time을 사용했다.