Last active
February 11, 2022 03:22
-
-
Save genghisjahn/0e1915b7b6c01c9125ee696efdd49158 to your computer and use it in GitHub Desktop.
Number Guessing Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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