Skip to content

Instantly share code, notes, and snippets.

@genghisjahn
Last active February 11, 2022 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genghisjahn/0e1915b7b6c01c9125ee696efdd49158 to your computer and use it in GitHub Desktop.
Save genghisjahn/0e1915b7b6c01c9125ee696efdd49158 to your computer and use it in GitHub Desktop.
Number Guessing Game
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
var n int
var g int
var c int
rand.Seed(int64(time.Now().Nanosecond()))
n = rand.Intn(100)
for {
fmt.Printf("Enter your guess: ")
fmt.Scanln(&g)
c = c + 1
if g == n {
fmt.Println("You guessed it!")
fmt.Println("No. Guesses: ", c)
break
} else if g > n {
fmt.Println("Too high.")
} else {
fmt.Println("Too low.")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment