Last active
July 18, 2020 15:58
-
-
Save jollyjoester/64c71fd384de2ea6da28484363b44b7f to your computer and use it in GitHub Desktop.
basic_golang_v2
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() { | |
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