forked from jim/Jogo-da-adivinhacao
50 lines
983 B
Go
50 lines
983 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
const TENTATIVAS = 3
|
|
numero := 7
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
fmt.Println("Bem-vindo ao jogo de adivinhação!")
|
|
fmt.Printf("Você tem %d tentativas para adivinhar o número entre 1 e 10.\n", TENTATIVAS)
|
|
|
|
// inicializando variável de tentativa
|
|
tentativa := 0
|
|
|
|
for tentativa < TENTATIVAS {
|
|
if tentativa == TENTATIVAS {
|
|
fmt.Println("Suas tentativas acabaram. O número correto era:", numero)
|
|
break
|
|
}
|
|
|
|
scanner.Scan()
|
|
chute := strings.TrimSpace(scanner.Text())
|
|
chuteInt, err := strconv.Atoi(chute)
|
|
|
|
if err != nil {
|
|
fmt.Println("Deve ser informado um número.")
|
|
continue
|
|
}
|
|
|
|
switch {
|
|
case chuteInt < numero:
|
|
fmt.Println("O número é maior, tente novamente.")
|
|
case chuteInt > numero:
|
|
fmt.Println("O número é menor, tente novamente.")
|
|
default:
|
|
fmt.Println("Parabéns! Você acertou o número!")
|
|
}
|
|
|
|
tentativa++
|
|
}
|
|
// comentario do Davi
|
|
}
|