Skip to content

Instantly share code, notes, and snippets.

@jollyjoester
Last active July 18, 2020 15:58
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 jollyjoester/64c71fd384de2ea6da28484363b44b7f to your computer and use it in GitHub Desktop.
Save jollyjoester/64c71fd384de2ea6da28484363b44b7f to your computer and use it in GitHub Desktop.
basic_golang_v2
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
answer := rand.Intn(10) + 1
count := 0
for {
var guess int
fmt.Print("Your guess? ")
fmt.Scanf("%v", &guess)
count++
if answer == guess {
fmt.Printf("Bingo! It took %v guessed!\n", count)
break
} else if answer > guess {
fmt.Println("The answer is higher!")
} else if answer < guess {
fmt.Println("The answer is lower!")
} else {
fmt.Println("Boo...")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment